Warning: This implementation has not been tested in production nor has it been examined by a security audit. All uses are your own responsibility.
A ruby implementation of Shamir's Secret Sharing.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install secret_sharing
This implementation of Shamir's Secret Sharing has initially been developed to be used in duse, however, it is designed to be used in any other context just as well.
The representation of a share is simply
x-hex(y). We chose this
representation, mainly to make it easier for this library to become compatible
with other implementations, if we choose to.
For better approximation and equal length of the resulting shares, a zero padding has been added. For example, if there are ten or more shares, then all single digit shares have a prepending zero.
Also, when generating a random polynomial, we make sure the coefficients are
random, but never zero. If we would allow the coefficients to be zero, it could
result in a lower threshold than intended. For example, if the threshold is
three, then the degree of the polynomial would be two so in the form of
f(x)=a0 + a1*x + a2*x^2. If
a2 would be zero than the polynomial would be
of dergree one, which would result in a real threshold of two rather than
require 'secret_sharing' shares = SecretSharing.split_secret('my secret', 2, 3) # => ["1-437b3d6cce8e7b77adb75", "2-86f673fa74e31127903f6", "3-ca71aa881b37a6d772c77"] length = shares.length # => 3 secret = SecretSharing.recover_secret(shares[0..1]) # => 'my secret'
- Fork it ( https://github.com/duse-io/secret_sharing_ruby/fork )
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create a new Pull Request