Class: RubyEventStore::Mappers::EncryptionKey
- Inherits:
-
Object
- Object
- RubyEventStore::Mappers::EncryptionKey
- Defined in:
- lib/ruby_event_store/mappers/encryption_key.rb
Instance Attribute Summary collapse
-
#cipher ⇒ Object
readonly
Returns the value of attribute cipher.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #decrypt(message, iv) ⇒ Object
- #encrypt(message, iv) ⇒ Object
-
#initialize(cipher:, key:) ⇒ EncryptionKey
constructor
A new instance of EncryptionKey.
- #random_iv ⇒ Object
Constructor Details
#initialize(cipher:, key:) ⇒ EncryptionKey
Returns a new instance of EncryptionKey.
6 7 8 9 |
# File 'lib/ruby_event_store/mappers/encryption_key.rb', line 6 def initialize(cipher:, key:) @cipher = cipher @key = key end |
Instance Attribute Details
#cipher ⇒ Object (readonly)
Returns the value of attribute cipher.
32 33 34 |
# File 'lib/ruby_event_store/mappers/encryption_key.rb', line 32 def cipher @cipher end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
32 33 34 |
# File 'lib/ruby_event_store/mappers/encryption_key.rb', line 32 def key @key end |
Instance Method Details
#decrypt(message, iv) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/ruby_event_store/mappers/encryption_key.rb', line 19 def decrypt(, iv) crypto = prepare_decrypt(cipher) crypto.iv = iv crypto.key = key ciphertext = crypto.authenticated? ? ciphertext_from_authenticated(crypto, ) : (crypto.update(ciphertext) + crypto.final).force_encoding("UTF-8") end |
#encrypt(message, iv) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/ruby_event_store/mappers/encryption_key.rb', line 11 def encrypt(, iv) crypto = prepare_encrypt(cipher) crypto.iv = iv crypto.key = key crypto.authenticated? ? encrypt_authenticated(crypto, ) : crypto.update() + crypto.final end |
#random_iv ⇒ Object
27 28 29 30 |
# File 'lib/ruby_event_store/mappers/encryption_key.rb', line 27 def random_iv crypto = prepare_encrypt(cipher) crypto.random_iv end |