Module: Strongbox::ClassMethods
- Defined in:
- lib/strongbox.rb
Instance Method Summary collapse
-
#encrypt_with_public_key(name, options = {}) ⇒ Object
encrypt_with_public_key
gives the class it is called on an attribute that when assigned is automatically encrypted using a public key. - #encrypt_with_symmetric_key(name, options = {}) ⇒ Object
- #strongbox_encryption(name, options) ⇒ Object
Instance Method Details
#encrypt_with_public_key(name, options = {}) ⇒ Object
encrypt_with_public_key
gives the class it is called on an attribute that when assigned is automatically encrypted using a public key. This allows the unattended encryption of data, without exposing the information need to decrypt it (as would be the case when using symmetric key encryption alone). Small amounts of data may be encrypted directly with the public key. Larger data is encrypted using symmetric encryption. The encrypted data is stored in the database column of the same name as the attibute. If symmetric encryption is used (the default) additional column are need to store the generated password and IV.
45 46 47 |
# File 'lib/strongbox.rb', line 45 def encrypt_with_public_key(name, = {}) strongbox_encryption( name, ) end |
#encrypt_with_symmetric_key(name, options = {}) ⇒ Object
49 50 51 52 |
# File 'lib/strongbox.rb', line 49 def encrypt_with_symmetric_key( name, = {}) .merge!( :symmetric => :only ) strongbox_encryption( name, ) end |
#strongbox_encryption(name, options) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/strongbox.rb', line 54 def strongbox_encryption( name, ) include InstanceMethods class_inheritable_reader :lock_options write_inheritable_attribute(:lock_options, {}) if .nil? [name] = .symbolize_keys.reverse_merge Strongbox. define_method name do lock_for(name) end define_method "#{name}=" do | plaintext | lock_for(name).encrypt plaintext end end |