Skip to content

Commit

Permalink
Merge pull request jmazzi#10 from jmazzi/bugfix/mysql_aes_base64
Browse files Browse the repository at this point in the history
Use Base64.encode/decode after/befor encrypting
  • Loading branch information
itspriddle committed Sep 14, 2012
2 parents 3084693 + 47cfb00 commit 3cb1e78
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/crypt_keeper/provider/mysql_aes.rb
Expand Up @@ -18,14 +18,16 @@ def initialize(options = {})
#
# Returns an encrypted string
def encrypt(value)
escape_and_execute_sql(["SELECT AES_ENCRYPT(?, ?)", value, key]).first
Base64.encode64 escape_and_execute_sql(
["SELECT AES_ENCRYPT(?, ?)", value, key]).first
end

# Public: Decrypts a string
#
# Returns a plaintext string
def decrypt(value)
escape_and_execute_sql(["SELECT AES_DECRYPT(?, ?)", value, key]).first
escape_and_execute_sql(
["SELECT AES_DECRYPT(?, ?)", Base64.decode64(value), key]).first
end

private
Expand Down
2 changes: 1 addition & 1 deletion spec/provider/mysql_aes_spec.rb
Expand Up @@ -11,7 +11,7 @@ module Provider
# into a spec :). This is a Base64 encoded string of 'test' AES encrypted
# by AES_ENCRYPT()
let(:cipher_text) do
Base64.decode64 "nbKOoWn8kvAw9k/C2Mex6Q==\n"
"nbKOoWn8kvAw9k/C2Mex6Q==\n"
end

subject { MysqlAes.new key: 'candy' }
Expand Down

0 comments on commit 3cb1e78

Please sign in to comment.