Class: Roro::Crypto::Cipher

Inherits:
Object
  • Object
show all
Defined in:
lib/roro.rb,
lib/roro/crypto/cipher.rb

Instance Method Summary collapse

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(options = {})
  @standard = options[:standard] || 'AES-128-CBC' 
  @salt     = options[: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_keyObject



13
14
15
# File 'lib/roro/crypto/cipher.rb', line 13

def generate_key
  Base64.encode64(@cipher.random_key)
end