Scrypty
This is a Rubygem that uses the scrypt algorithm to encrypt/decrypt data. The 'scrypt' gem only provides support for hashing passwords.
Installation
Add this line to your application's Gemfile:
gem 'scrypty'
And then execute:
$ bundle
Or install it yourself as:
$ gem install scrypty
Usage
The scrypt algorithm uses a few parameters to determine how to encrypt data:
- maxmem - use at most the specified number of bytes of RAM when computing the derived encryption key (use 0 for unlimited)
- maxmemfrac - use at most the specified fraction of the available RAM for computing the derived encryption key
- maxtime - spend at most maxtime seconds computing the derived encryption key from the password
Example:
require 'scrypty'
data = "my data"
password = "secret"
maxmem = 0
maxmemfrac = 0.125
maxtime = 5.0
encrypted = Scrypty.encrypt(data, password, maxmem, maxmemfrac, maxtime)
puts "Encrypted data: #{encrypted.inspect}"
decrypted = Scrypty.decrypt(encrypted, password, maxmem, maxmemfrac, maxtime)
puts "Decrypted data: #{decrypted.inspect}"
orig_fn = "foo.txt"
enc_fn = "foo.dat"
dec_fn = "foo-dec.txt"
File.open(orig_fn, "w") { |f| f.print("my data") }
Scrypty.encrypt_file(orig_fn, enc_fn, password, maxmem, maxmemfrac, maxtime)
puts "Encrypted file: #{File.read(enc_fn).inspect}"
Scrypty.decrypt_file(enc_fn, dec_fn, password, maxmem, maxmemfrac, maxtime)
puts "Decrypted file: #{File.read(dec_fn).inspect}"
See also
Contributing
- Fork it
- 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 new Pull Request