Sha256: 6cb906aed878d48da9064813f1af436a5536e1b205e4537073b44c89490eb394

Contents?: true

Size: 928 Bytes

Versions: 5

Compression:

Stored size: 928 Bytes

Contents

require 'crypt_keeper/log_subscriber/postgres_pgp'

module CryptKeeper
  module Provider
    class PostgresPgp
      include CryptKeeper::Helper::SQL
      attr_accessor :key

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

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

      # Public: Encrypts a string
      #
      # Returns an encrypted string
      def encrypt(value)
        escape_and_execute_sql(["SELECT pgp_sym_encrypt(?, ?)", value.to_s, key])['pgp_sym_encrypt']
      end

      # Public: Decrypts a string
      #
      # Returns a plaintext string
      def decrypt(value)
        escape_and_execute_sql(["SELECT pgp_sym_decrypt(?, ?)", value, key])['pgp_sym_decrypt']
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
crypt_keeper-0.12.0 lib/crypt_keeper/provider/postgres_pgp.rb
crypt_keeper-0.11.0 lib/crypt_keeper/provider/postgres_pgp.rb
crypt_keeper-0.10.0.pre lib/crypt_keeper/provider/postgres_pgp.rb
crypt_keeper-0.9.0.pre lib/crypt_keeper/provider/postgres_pgp.rb
crypt_keeper-0.8.0 lib/crypt_keeper/provider/postgres_pgp.rb