Class: Roro::Crypto::Cipher
- Inherits:
-
Object
- Object
- Roro::Crypto::Cipher
- Defined in:
- lib/roro.rb,
lib/roro/crypto/cipher.rb
Instance Method Summary collapse
- #decrypt(encrypted, key) ⇒ Object
- #encrypt(decrypted, key) ⇒ Object
- #generate_key ⇒ Object
-
#initialize(options = {}) ⇒ Cipher
constructor
A new instance of Cipher.
Constructor Details
#initialize(options = {}) ⇒ Cipher
Returns a new instance of Cipher.
7 8 9 10 11 |
# File 'lib/roro/crypto/cipher.rb', line 7 def initialize( = {}) @standard = [:standard] || 'AES-128-CBC' @salt = [:salt] || '8 octets' @cipher = OpenSSL::Cipher.new @standard end |
Instance Method Details
#decrypt(encrypted, key) ⇒ Object
22 23 24 25 26 |
# File 'lib/roro/crypto/cipher.rb', line 22 def decrypt(encrypted, key) build_cipher(key) @cipher.decrypt.pkcs5_keyivgen @key, @salt @cipher.update(Base64.decode64 encrypted) + @cipher.final end |
#encrypt(decrypted, key) ⇒ Object
17 18 19 20 |
# File 'lib/roro/crypto/cipher.rb', line 17 def encrypt(decrypted, key) build_cipher(key) Base64.encode64(@cipher.update(decrypted) + @cipher.final) end |
#generate_key ⇒ Object
13 14 15 |
# File 'lib/roro/crypto/cipher.rb', line 13 def generate_key Base64.encode64(@cipher.random_key) end |