Class: RomEncryptedAttribute::Encryptor
- Inherits:
-
Object
- Object
- RomEncryptedAttribute::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.
10 11 12 |
# File 'lib/rom_encrypted_attribute/encryptor.rb', line 10 def initialize(derivator:) @derivator = derivator end |
Instance Method Details
#encrypt(message) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rom_encrypted_attribute/encryptor.rb', line 14 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 |