Sha256: 44f292b87207467c1ec3aeae794dc90088e1ca53b2144fa82c4bc0acf7fa09fd

Contents?: true

Size: 1.14 KB

Versions: 13

Compression:

Stored size: 1.14 KB

Contents

require 'crypt_keeper/log_subscriber/mysql_aes'

module CryptKeeper
  module Provider
    class MysqlAes
      include CryptKeeper::Helper::SQL

      attr_accessor :key

      # Public: Initializes the encryptor
      #
      #  options - A hash, :key is required
      def initialize(options = {})
        legacy
        ActiveSupport.run_load_hooks(:crypt_keeper_mysql_aes_log, self)

        @key = options.fetch(:key) do
          raise ArgumentError, "Missing :key"
        end
      end

      # Public: Encrypts a string
      #
      # Returns an encrypted string
      def encrypt(value)
        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(?, ?)", Base64.decode64(value), key]).first
      end

      private

      def legacy
        unless ENV['CRYPT_KEEPER_IGNORE_LEGACY_DEPRECATION']
          warn "[DEPRECATION] MySqlAes Legacy is now deprecated. Please see http://git.io/nXXOlg"
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
crypt_keeper-0.22.0 lib/crypt_keeper/provider/mysql_aes.rb
crypt_keeper-0.21.0 lib/crypt_keeper/provider/mysql_aes.rb
crypt_keeper-0.20.0 lib/crypt_keeper/provider/mysql_aes.rb
crypt_keeper-0.19.0 lib/crypt_keeper/provider/mysql_aes.rb
crypt_keeper-0.18.4 lib/crypt_keeper/provider/mysql_aes.rb
crypt_keeper-0.18.3 lib/crypt_keeper/provider/mysql_aes.rb
crypt_keeper-0.18.2 lib/crypt_keeper/provider/mysql_aes.rb
crypt_keeper-0.18.1 lib/crypt_keeper/provider/mysql_aes.rb
crypt_keeper-0.18.0 lib/crypt_keeper/provider/mysql_aes.rb
crypt_keeper-0.17.0 lib/crypt_keeper/provider/mysql_aes.rb
crypt_keeper-0.16.1 lib/crypt_keeper/provider/mysql_aes.rb
crypt_keeper-0.16.0 lib/crypt_keeper/provider/mysql_aes.rb
crypt_keeper-0.16.0.pre lib/crypt_keeper/provider/mysql_aes.rb