class CryptKeeper::Provider::ActiveSupport
Attributes
encryptor[R]
Public Class Methods
new(options = {})
click to toggle source
Public: Initializes the encryptor
options - A hash, :key and :salt are required
Returns nothing.
# File lib/crypt_keeper/provider/active_support.rb, line 13 def initialize(options = {}) key = options.fetch(:key) salt = options.fetch(:salt) @encryptor = ::ActiveSupport::MessageEncryptor.new \ ::ActiveSupport::KeyGenerator.new(key).generate_key(salt, 32) end
Public Instance Methods
decrypt(value)
click to toggle source
Public: Decrypts a string
value - Cipher text
Returns a plaintext string
# File lib/crypt_keeper/provider/active_support.rb, line 35 def decrypt(value) encryptor.decrypt_and_verify(value) end
encrypt(value)
click to toggle source
Public: Encrypts a string
value - Plaintext value
Returns an encrypted string
# File lib/crypt_keeper/provider/active_support.rb, line 26 def encrypt(value) encryptor.encrypt_and_sign(value) end
search(records, field, criteria)
click to toggle source
Public: Searches the table
records - ActiveRecord::Relation field - Field name to match criteria - Value to match
Returns an Enumerable
# File lib/crypt_keeper/provider/active_support.rb, line 46 def search(records, field, criteria) records.select { |record| record[field] == criteria } end