Class: ActiveEncryption::EncryptionSetting::Key
- Inherits:
-
Object
- Object
- ActiveEncryption::EncryptionSetting::Key
- Defined in:
- lib/active_encryption/encryption_setting/key.rb
Overview
The ActiveEncryption::EncryptionSetting::Key class wraps around ActiveSupport::KeyGenerator
Constant Summary collapse
- DEFAULT_SALT =
'ActiveEncryption default key salt'
Instance Attribute Summary collapse
-
#iterations ⇒ Object
readonly
Returns the value of attribute iterations.
-
#salt ⇒ Object
readonly
Returns the value of attribute salt.
Instance Method Summary collapse
- #cipher ⇒ Object
-
#initialize(secret, salt: nil, cipher: nil, iterations: nil) ⇒ Key
constructor
A new instance of Key.
- #length ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(secret, salt: nil, cipher: nil, iterations: nil) ⇒ Key
Returns a new instance of Key.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/active_encryption/encryption_setting/key.rb', line 15 def initialize(secret, salt: nil, cipher: nil, iterations: nil) salt ||= DEFAULT_SALT @salt = salt @cipher = cipher @iterations = iterations @generator = ActiveSupport::KeyGenerator.new( secret, iterations: iterations ) end |
Instance Attribute Details
#iterations ⇒ Object (readonly)
Returns the value of attribute iterations.
13 14 15 |
# File 'lib/active_encryption/encryption_setting/key.rb', line 13 def iterations @iterations end |
#salt ⇒ Object (readonly)
Returns the value of attribute salt.
13 14 15 |
# File 'lib/active_encryption/encryption_setting/key.rb', line 13 def salt @salt end |
Instance Method Details
#cipher ⇒ Object
30 31 32 |
# File 'lib/active_encryption/encryption_setting/key.rb', line 30 def cipher @cipher ||= ActiveSupport::MessageEncryptor.default_cipher end |
#length ⇒ Object
34 35 36 |
# File 'lib/active_encryption/encryption_setting/key.rb', line 34 def length ActiveSupport::MessageEncryptor.key_len(cipher) end |
#value ⇒ Object
26 27 28 |
# File 'lib/active_encryption/encryption_setting/key.rb', line 26 def value @generator.generate_key(salt, length) end |