Class: CryptKeeper::Provider::ActiveSupport
- Defined in:
- lib/crypt_keeper/provider/active_support.rb
Instance Attribute Summary collapse
-
#encryptor ⇒ Object
readonly
Returns the value of attribute encryptor.
Instance Method Summary collapse
-
#decrypt(value) ⇒ Object
Public: Decrypts a string.
-
#encrypt(value) ⇒ Object
Public: Encrypts a string.
-
#initialize(options = {}) ⇒ ActiveSupport
constructor
Public: Initializes the encryptor.
-
#search(records, field, criteria) ⇒ Object
Public: Searches the table.
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ ActiveSupport
Public: Initializes the encryptor
options - A hash, :key and :salt are required
Returns nothing.
13 14 15 16 17 18 19 |
# File 'lib/crypt_keeper/provider/active_support.rb', line 13 def initialize( = {}) key = .fetch(:key) salt = .fetch(:salt) @encryptor = ::ActiveSupport::MessageEncryptor.new \ ::ActiveSupport::KeyGenerator.new(key).generate_key(salt, 32) end |
Instance Attribute Details
#encryptor ⇒ Object (readonly)
Returns the value of attribute encryptor.
6 7 8 |
# File 'lib/crypt_keeper/provider/active_support.rb', line 6 def encryptor @encryptor end |
Instance Method Details
#decrypt(value) ⇒ Object
Public: Decrypts a string
value - Cipher text
Returns a plaintext string
35 36 37 |
# File 'lib/crypt_keeper/provider/active_support.rb', line 35 def decrypt(value) encryptor.decrypt_and_verify(value) end |
#encrypt(value) ⇒ Object
Public: Encrypts a string
value - Plaintext value
Returns an encrypted string
26 27 28 |
# File 'lib/crypt_keeper/provider/active_support.rb', line 26 def encrypt(value) encryptor.encrypt_and_sign(value) end |
#search(records, field, criteria) ⇒ Object
Public: Searches the table
records - ActiveRecord::Relation field - Field name to match criteria - Value to match
Returns an Enumerable
46 47 48 |
# File 'lib/crypt_keeper/provider/active_support.rb', line 46 def search(records, field, criteria) records.select { |record| record[field] == criteria } end |