Class: Hide
- Inherits:
-
Object
- Object
- Hide
- Defined in:
- lib/hide.rb
Defined Under Namespace
Classes: AE
Class Method Summary collapse
- .decrypt(data, key, salt, iter, iv, key_length) ⇒ Object
- .encrypt(data, key, salt, iter, iv = SecureRandom.random_bytes(16), key_length = 32) ⇒ Object
Class Method Details
.decrypt(data, key, salt, iter, iv, key_length) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/hide.rb', line 18 def decrypt data, key, salt, iter, iv, key_length decipher = OpenSSL::Cipher.new 'AES-256-CBC' decipher.decrypt decipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, iter, key_length) decipher.iv = iv decipher.update(data) + decipher.final end |
.encrypt(data, key, salt, iter, iv = SecureRandom.random_bytes(16), key_length = 32) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/hide.rb', line 6 def encrypt data, key, salt, iter, iv=SecureRandom.random_bytes(16), key_length = 32 cipher = OpenSSL::Cipher.new 'AES-256-CBC' cipher.encrypt cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, iter, key_length) cipher.iv = iv { data: cipher.update(data) + cipher.final, iv: iv } end |