Module: Encryptor::Private
- Included in:
- User
- Defined in:
- lib/encryptor.rb
Instance Method Summary collapse
- #aes_decrypt(ciphertext, key) ⇒ Object
- #decrypt(cipher_json) ⇒ Object
- #get_aes_key(encrypted_key) ⇒ Object
Instance Method Details
#aes_decrypt(ciphertext, key) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/encryptor.rb', line 50 def aes_decrypt(ciphertext, key) cipher = OpenSSL::Cipher.new('AES-256-CBC') cipher.decrypt cipher.key = Base64.decode64 key['key'] cipher.iv = Base64.decode64 key['iv'] txt = '' txt << cipher.update(Base64.decode64 ciphertext) txt << cipher.final txt end |
#decrypt(cipher_json) ⇒ Object
39 40 41 42 43 |
# File 'lib/encryptor.rb', line 39 def decrypt cipher_json json = JSON.parse(Base64.decode64 cipher_json) aes_key = get_aes_key json['aes_key'] aes_decrypt(json['ciphertext'], aes_key) end |
#get_aes_key(encrypted_key) ⇒ Object
45 46 47 48 |
# File 'lib/encryptor.rb', line 45 def get_aes_key encrypted_key clear_key = encryption_key.private_decrypt( Base64.decode64 encrypted_key ) JSON::parse(clear_key) end |