class CryptKeeper::Provider::MysqlAesNew
Attributes
key[RW]
Public Class Methods
new(options = {})
click to toggle source
Public: Initializes the encryptor
options - A hash, :key and :salt are required
# File lib/crypt_keeper/provider/mysql_aes_new.rb, line 14 def initialize(options = {}) ::ActiveSupport.run_load_hooks(:crypt_keeper_mysql_aes_log, self) @key = digest_passphrase(options[:key], options[:salt]) end
Public Instance Methods
decrypt(value)
click to toggle source
Public: Decrypts a string
Returns a plaintext string
# File lib/crypt_keeper/provider/mysql_aes_new.rb, line 30 def decrypt(value) escape_and_execute_sql( ["SELECT AES_DECRYPT(?, ?)", Base64.decode64(value), key]).first end
encrypt(value)
click to toggle source
Public: Encrypts a string
Returns an encrypted string
# File lib/crypt_keeper/provider/mysql_aes_new.rb, line 22 def encrypt(value) Base64.encode64 escape_and_execute_sql( ["SELECT AES_ENCRYPT(?, ?)", value, key]).first end
search(records, field, criteria)
click to toggle source
Public: Searches the table
Returns an Enumerable
# File lib/crypt_keeper/provider/mysql_aes_new.rb, line 38 def search(records, field, criteria) records.where("#{field} = ?", encrypt(criteria)) end