Class: Lazylead::Salt
- Inherits:
-
Object
- Object
- Lazylead::Salt
- Defined in:
- lib/lazylead/salt.rb
Overview
A cryptography salt defined in environment variables.
Salt is random data that is used as an additional input to a one-way function that hashes data, a password or passphrase. Salts are used to safeguard passwords in storage. Historically a password was stored in plaintext on a system, but over time additional safeguards developed to protect a user’s password against being read from the system. A salt is one of those methods.
Read more: en.wikipedia.org/wiki/Salt_(cryptography).
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #decrypt(password) ⇒ Object
- #encrypt(password) ⇒ Object
-
#initialize(id, env = ENV.to_h) ⇒ Salt
constructor
Each salt should be defined as a environment variable with id, like salt1=E1F53135E559C253 salt2=84B03D034B409D4E …
- #specified? ⇒ Boolean
Constructor Details
#initialize(id, env = ENV.to_h) ⇒ Salt
Each salt should be defined as a environment variable with id, like
salt1=E1F53135E559C253
salt2=84B03D034B409D4E
...
saltN=xxxxxxxxx
49 50 51 52 |
# File 'lib/lazylead/salt.rb', line 49 def initialize(id, env = ENV.to_h) @id = id @env = env end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
41 42 43 |
# File 'lib/lazylead/salt.rb', line 41 def id @id end |
Instance Method Details
#decrypt(password) ⇒ Object
58 59 60 |
# File 'lib/lazylead/salt.rb', line 58 def decrypt(password) ActiveSupport::MessageEncryptor.new(@env[@id]).decrypt_and_verify password end |
#encrypt(password) ⇒ Object
54 55 56 |
# File 'lib/lazylead/salt.rb', line 54 def encrypt(password) ActiveSupport::MessageEncryptor.new(@env[@id]).encrypt_and_sign password end |
#specified? ⇒ Boolean
62 63 64 |
# File 'lib/lazylead/salt.rb', line 62 def specified? @env.key?(@id) && !@env[@id].blank? end |