Class: Phronomy::StateStore::Encryptor::ActiveSupport
- Defined in:
- lib/phronomy/state_store/encryptor/active_support.rb
Overview
Encryptor backed by ActiveSupport::MessageEncryptor.
Requires the +activesupport+ gem to be available in the host application. Does NOT require rails — any Ruby project that depends on activesupport can use this adapter.
Instance Method Summary collapse
-
#decrypt(ciphertext) ⇒ String
Decrypts and verifies the ciphertext.
-
#encrypt(plaintext) ⇒ String
Encrypts the plaintext using AES-256-GCM.
-
#initialize(secret_key_base:, cipher: "aes-256-gcm") ⇒ ActiveSupport
constructor
A new instance of ActiveSupport.
Constructor Details
#initialize(secret_key_base:, cipher: "aes-256-gcm") ⇒ ActiveSupport
Returns a new instance of ActiveSupport.
25 26 27 28 29 30 |
# File 'lib/phronomy/state_store/encryptor/active_support.rb', line 25 def initialize(secret_key_base:, cipher: "aes-256-gcm") require "active_support/message_encryptor" key = ::ActiveSupport::KeyGenerator.new(secret_key_base) .generate_key("phronomy state store", 32) @encryptor = ::ActiveSupport::MessageEncryptor.new(key, cipher: cipher) end |
Instance Method Details
#decrypt(ciphertext) ⇒ String
Decrypts and verifies the ciphertext.
43 44 45 |
# File 'lib/phronomy/state_store/encryptor/active_support.rb', line 43 def decrypt(ciphertext) @encryptor.decrypt_and_verify(ciphertext) end |
#encrypt(plaintext) ⇒ String
Encrypts the plaintext using AES-256-GCM.
35 36 37 |
# File 'lib/phronomy/state_store/encryptor/active_support.rb', line 35 def encrypt(plaintext) @encryptor.encrypt_and_sign(plaintext) end |