Class: ROM::EncryptedAttribute::Encryptor
- Inherits:
-
Object
- Object
- ROM::EncryptedAttribute::Encryptor
- Defined in:
- lib/rom/encrypted_attribute/encryptor.rb
Instance Method Summary collapse
- #encrypt(message) ⇒ Object
-
#initialize(derivator:) ⇒ Encryptor
constructor
A new instance of Encryptor.
Constructor Details
#initialize(derivator:) ⇒ Encryptor
Returns a new instance of Encryptor.
11 12 13 |
# File 'lib/rom/encrypted_attribute/encryptor.rb', line 11 def initialize(derivator:) @derivator = derivator end |
Instance Method Details
#encrypt(message) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rom/encrypted_attribute/encryptor.rb', line 15 def encrypt() cipher = OpenSSL::Cipher.new("aes-256-gcm") key = @derivator.derive(cipher.key_len) iv = cipher.random_iv cipher.encrypt cipher.key = key cipher.iv = iv encrypted = cipher.update() + cipher.final Payload.new(message: encrypted, initialization_vector: iv, auth_tag: cipher.auth_tag).encode end |