Class: CryptKeeperProviders::PostgresPgp
- Inherits:
-
Object
- Object
- CryptKeeperProviders::PostgresPgp
- Defined in:
- lib/crypt_keeper_providers/postgres_pgp.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
-
#decrypt(value) ⇒ Object
Public: Decrypts a string.
-
#encrypt(value) ⇒ Object
Public: Encrypts a string.
-
#initialize(options = {}) ⇒ PostgresPgp
constructor
Public: Initializes the encryptor.
Constructor Details
#initialize(options = {}) ⇒ PostgresPgp
Public: Initializes the encryptor
options - A hash, :key is required
10 11 12 13 14 |
# File 'lib/crypt_keeper_providers/postgres_pgp.rb', line 10 def initialize( = {}) @key = .fetch(:key) do raise ArgumentError, "Missing :key" end end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
5 6 7 |
# File 'lib/crypt_keeper_providers/postgres_pgp.rb', line 5 def key @key end |
Instance Method Details
#decrypt(value) ⇒ Object
Public: Decrypts a string
Returns a plaintext string
26 27 28 |
# File 'lib/crypt_keeper_providers/postgres_pgp.rb', line 26 def decrypt(value) escape_and_execute_sql(["SELECT pgp_sym_decrypt(?, ?)", value, key])['pgp_sym_decrypt'] end |
#encrypt(value) ⇒ Object
Public: Encrypts a string
Returns an encrypted string
19 20 21 |
# File 'lib/crypt_keeper_providers/postgres_pgp.rb', line 19 def encrypt(value) escape_and_execute_sql(["SELECT pgp_sym_encrypt(?, ?)", value, key])['pgp_sym_encrypt'] end |