Module: AttrEncryptedPgcrypto::Encryptor

Extended by:
Encryptor
Included in:
Encryptor
Defined in:
lib/attr_encrypted_pgcrypto/encryptor.rb

Instance Method Summary collapse

Instance Method Details

#decrypt(*args, &block) ⇒ Object

Decrypts a :value with a specified :key

Example

decrypted_value = AttrEncryptedPgcrypto::Encryptor.decrypt(:value => 'some encrypted string', :key => 'some secret key')
# or
decrypted_value = AttrEncryptedPgcrypto::Encryptor.decrypt('some encrypted string', :key => 'some secret key')


25
26
27
# File 'lib/attr_encrypted_pgcrypto/encryptor.rb', line 25

def decrypt(*args, &block)
  escape_and_execute_sql(["SELECT pgp_sym_decrypt(?, ?)", value(args), key(args)])['pgp_sym_decrypt']
end

#encrypt(*args, &block) ⇒ Object

Encrypts a :value with a specified :key

Example

encrypted_value = AttrEncryptedPgcrypto::Encryptor.encrypt(:value => 'some string to encrypt', :key => 'some secret key')
# or
encrypted_value = AttrEncryptedPgcrypto::Encryptor.encrypt('some string to encrypt', :key => 'some secret key')


14
15
16
# File 'lib/attr_encrypted_pgcrypto/encryptor.rb', line 14

def encrypt(*args, &block)
  escape_and_execute_sql(["SELECT pgp_sym_encrypt(?, ?)", value(args), key(args)])['pgp_sym_encrypt']
end