Sha256: bbe124034aa3350d3bc910ce5612d9d59f23659351b2554bba6f88f740e481c5

Contents?: true

Size: 853 Bytes

Versions: 3

Compression:

Stored size: 853 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 = {})
        @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

3 entries across 3 versions & 1 rubygems

Version Path
crypt_keeper-0.7.0 lib/crypt_keeper/provider/postgres_pgp.rb
crypt_keeper-0.6.1 lib/crypt_keeper/provider/postgres_pgp.rb
crypt_keeper-0.6.0 lib/crypt_keeper/provider/postgres_pgp.rb