Sha256: 1bdf5d92b01da6f9cc571f5b3424f17f6757ea781686fb356db775483a6a13db
Contents?: true
Size: 1.17 KB
Versions: 1
Compression:
Stored size: 1.17 KB
Contents
require 'crypt_keeper/log_subscriber/postgres_pgp' module CryptKeeper module Provider class PostgresPgp include CryptKeeper::Helper::SQL attr_accessor :key attr_accessor :pgcrypto_options # 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 @pgcrypto_options = options.fetch(:pgcrypto_options, '') end # Public: Encrypts a string # # Returns an encrypted string def encrypt(value) escape_and_execute_sql(["SELECT pgp_sym_encrypt(?, ?, ?)", value.to_s, key, pgcrypto_options])['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 def search(records, field, criteria) records.where("(pgp_sym_decrypt(cast(#{field} AS bytea), ?) = ?)", key, criteria) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
crypt_keeper-0.15.0.pre | lib/crypt_keeper/provider/postgres_pgp.rb |