Class: Envault::Cryptor::Simple
- Inherits:
-
Object
- Object
- Envault::Cryptor::Simple
- Defined in:
- lib/envault/cryptor/simple.rb
Instance Method Summary collapse
- #decrypt(value) ⇒ Object
- #encrypt(value) ⇒ Object
-
#initialize(profile) ⇒ Simple
constructor
A new instance of Simple.
Constructor Details
#initialize(profile) ⇒ Simple
Returns a new instance of Simple.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/envault/cryptor/simple.rb', line 4 def initialize(profile) passphrase = profile[:passphrase] || '' sign_passphrase = profile[:sign_passphrase] salt = profile[:salt] || '' key = ActiveSupport::KeyGenerator.new(passphrase).generate_key(salt, 32) signature_key = ActiveSupport::KeyGenerator.new(sign_passphrase).generate_key(salt, 32) if sign_passphrase if signature_key @cryptor = ActiveSupport::MessageEncryptor.new(key, signature_key, cipher: DEFAULT_CIPHER, digest: DEFAULT_DIGEST) else @cryptor = ActiveSupport::MessageEncryptor.new(key, cipher: DEFAULT_CIPHER, digest: DEFAULT_DIGEST) end end |
Instance Method Details
#decrypt(value) ⇒ Object
23 24 25 |
# File 'lib/envault/cryptor/simple.rb', line 23 def decrypt(value) @cryptor.decrypt_and_verify(value) end |
#encrypt(value) ⇒ Object
19 20 21 |
# File 'lib/envault/cryptor/simple.rb', line 19 def encrypt(value) @cryptor.encrypt_and_sign(value) end |