module Hide

The primary module for hide

Provides basic encryption/decryption support

Constants

VERSION

Gem version specifier

Public Instance Methods

decrypt(data, key, salt, iter, iv, key_length = 32) click to toggle source

Decrypts any datastream with provided decryption credential and configuration.

This method does not provide support for authenticated encryption. For authenticated encryption support, please use Hide::AE module

Returns the decrypted data

   # File lib/hide.rb
37 def decrypt data, key, salt, iter, iv, key_length = 32
38   decipher = OpenSSL::Cipher.new "AES-256-CBC"
39   decipher.decrypt
40   decipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, iter, key_length)
41   decipher.iv = iv
42   decipher.update(data) + decipher.final
43 end
encrypt( data, key, salt, iter, iv = SecureRandom.random_bytes(16), key_length = 32 ) click to toggle source

Encrypts a data stream without any authentication identifier.

For authenticated encryption support please use Hide::AE module

Returns a hash containing encrypted data and IV

   # File lib/hide.rb
17 def encrypt(
18   data, key, salt, iter, iv = SecureRandom.random_bytes(16), key_length = 32
19 )
20   cipher = OpenSSL::Cipher.new "AES-256-CBC"
21   cipher.encrypt
22   cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, salt, iter, key_length)
23   cipher.iv = iv
24   {
25     data: cipher.update(data) + cipher.final,
26     iv: iv
27   }
28 end