Class: CryptKeeper::Provider::MysqlAesNew
- Includes:
- Helper::DigestPassphrase, Helper::SQL
- Defined in:
- lib/crypt_keeper/provider/mysql_aes_new.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
-
#decrypt(value) ⇒ Object
Public: Decrypts a string.
-
#encrypt(value) ⇒ Object
Public: Encrypts a string.
-
#initialize(options = {}) ⇒ MysqlAesNew
constructor
Public: Initializes the encryptor.
-
#search(records, field, criteria) ⇒ Object
Public: Searches the table.
Methods included from Helper::DigestPassphrase
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ MysqlAesNew
Public: Initializes the encryptor
options - A hash, :key and :salt are required
14 15 16 17 |
# File 'lib/crypt_keeper/provider/mysql_aes_new.rb', line 14 def initialize( = {}) ::ActiveSupport.run_load_hooks(:crypt_keeper_mysql_aes_log, self) @key = digest_passphrase([:key], [:salt]) end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
9 10 11 |
# File 'lib/crypt_keeper/provider/mysql_aes_new.rb', line 9 def key @key end |
Instance Method Details
#decrypt(value) ⇒ Object
Public: Decrypts a string
Returns a plaintext string
30 31 32 33 |
# 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) ⇒ Object
Public: Encrypts a string
Returns an encrypted string
22 23 24 25 |
# 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) ⇒ Object
Public: Searches the table
Returns an Enumerable
38 39 40 |
# File 'lib/crypt_keeper/provider/mysql_aes_new.rb', line 38 def search(records, field, criteria) records.where("#{field} = ?", encrypt(criteria)) end |