Class: Ibrain::Encryptor
- Inherits:
-
Object
- Object
- Ibrain::Encryptor
- Defined in:
- lib/ibrain/encryptor.rb
Overview
Ibrain::Encryptor is a thin wrapper around ActiveSupport::MessageEncryptor.
Instance Method Summary collapse
-
#decrypt(encrypted_value) ⇒ String
Decrypt an encrypted value.
-
#encrypt(value) ⇒ String
Encrypt a value.
-
#initialize(key = Ibrain::Config.ibrain_encryptor_key) ⇒ Encryptor
constructor
A new instance of Encryptor.
Constructor Details
#initialize(key = Ibrain::Config.ibrain_encryptor_key) ⇒ Encryptor
Returns a new instance of Encryptor.
7 8 9 10 11 |
# File 'lib/ibrain/encryptor.rb', line 7 def initialize(key = Ibrain::Config.ibrain_encryptor_key) key = Rails.application.secrets.secret_key_base.byteslice(0..31) if key.blank? @crypt = ActiveSupport::MessageEncryptor.new(key) end |
Instance Method Details
#decrypt(encrypted_value) ⇒ String
Decrypt an encrypted value
23 24 25 |
# File 'lib/ibrain/encryptor.rb', line 23 def decrypt(encrypted_value) @crypt.decrypt_and_verify(encrypted_value) end |
#encrypt(value) ⇒ String
Encrypt a value
16 17 18 |
# File 'lib/ibrain/encryptor.rb', line 16 def encrypt(value) @crypt.encrypt_and_sign(value) end |