Module: Cryptonite::ClassMethods

Defined in:
lib/cryptonite.rb

Instance Method Summary collapse

Instance Method Details

#attr_encrypted(*attributes) ⇒ Object

Attributes listed as encrypted will be transparently encrypted and decrypted in database operations.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cryptonite.rb', line 23

def attr_encrypted(*attributes)
  options = attributes.extract_options!

  @public_key = get_rsa_key(options[:public_key] || options[:key_pair] || ENV['PUBLIC_KEY'])
  @private_key = get_rsa_key(options[:private_key] || options[:key_pair] || ENV['PRIVATE_KEY'], options[:private_key_password] || ENV['PRIVATE_KEY_PASSWORD'])

  for attribute in attributes do
    serialize attribute, Coder.new(@private_key || @public_key)
  end

  self._attr_encrypted = Set.new(attributes.map { |a| a.to_s }) + (self._attr_encrypted || [])
end

#encrypted_attributesObject

Returns an array of all the attributes that have been specified as encrypted.



37
38
39
# File 'lib/cryptonite.rb', line 37

def encrypted_attributes
  self._attr_encrypted
end