Module: Duse::Encryption::Symmetric
Instance Method Summary collapse
Methods included from Encoding
Instance Method Details
#decrypt(key, iv, cipher_text) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/duse/encryption.rb', line 61 def decrypt(key, iv, cipher_text) key = decode(key) iv = decode(iv) cipher_text = decode(cipher_text) cipher = symmetric_algorithm cipher.decrypt cipher.key = key cipher.iv = iv plaintext = cipher.update(cipher_text) plaintext << cipher.final decode(plaintext) end |
#encrypt(plaintext) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/duse/encryption.rb', line 48 def encrypt(plaintext) plaintext = encode(plaintext) cipher = symmetric_algorithm cipher.encrypt key = cipher.random_key iv = cipher.random_iv cipher_text = cipher.update(plaintext) cipher_text << cipher.final [encode(key), encode(iv), encode(cipher_text)] end |
#symmetric_algorithm ⇒ Object
76 77 78 |
# File 'lib/duse/encryption.rb', line 76 def symmetric_algorithm OpenSSL::Cipher.new('AES-256-CBC') end |