Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including cryptomancy-shard with all npm packages installed. Try it out:

var cryptomancyShard = require("cryptomancy-shard")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

cryptomancy-shard v2.0.0

really basic secret sharing based on xor

Cryptomancy-shard

For secret-sharing schemes which need support for threshold recombination there's cryptomancy-secret. If your needs are incredibly simple, this module may provide a simpler option.

Its goal is to be:

  • small
  • fast
  • flexible
  • readable
  • secure

It's missing:

  • threshold support
  • authentication
  • padding bytes

Use

// the API takes and outputs Uint8Arrays
// so you'll probably want to convert between that and different formats
var Format = require("cryptomancy-format");

// it expects you to supply your own randomness
// so it can be deterministic if that suits your needs
// otherwise use a cryptographically secure source of random bytes
var Source = require("cryptomancy-source");
var secure_bytes = Source.bytes.secure();

var plaintext = "PEW PEW PEW";
var u8_message = Format.decodeUTF8(plaintext);

// load the library
var Shard = require("cryptomancy-shard");

// split the plaintext up into 5 shards
// all of which are necessary to reproduce the original value
var shards = Shard.split(secure_bytes, u8_message, 5);

// print out your shards in whatever format you like
// I like base64 because they're probably not valid UTF8
// and I don't like hex
console.log(shards.map(Format.encode64));

// join the shards
// order doesn't matter because internally it's just xor'ing the values
var recovered = Format.encodeUTF8(Shard.join(shards));

console.log(recovered);
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free