Module: Encrypt
- Defined in:
- lib/encrypt.rb,
lib/encrypt/version.rb
Constant Summary collapse
- VERSION =
'0.1.0'
Class Method Summary collapse
Class Method Details
.dump(string, key) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/encrypt.rb', line 4 def self.dump string, key cipher = OpenSSL::Cipher::AES256.new(:CBC) cipher.encrypt salt = OpenSSL::Random.random_bytes(16) cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, 20000, 32) iv = cipher.random_iv Marshal.dump([salt, iv, cipher.update(string) << cipher.final]) end |
.load(string, key) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/encrypt.rb', line 13 def self.load string, key salt, iv, encrypted = Marshal.load(string) cipher = OpenSSL::Cipher::AES256.new(:CBC) cipher.decrypt cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, 20000, 32) cipher.iv = iv cipher.update(encrypted) << cipher.final end |