Module: Encryptor

Extended by:
ActiveSupport::Concern
Defined in:
lib/encryptor.rb,
lib/encryptor/version.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VERSION =
'0.0.2'

Instance Method Summary collapse

Instance Method Details

#decrypt(encrypted_attribute, key) ⇒ Object

Preconditions => encrypted_attribute - string, it is the encrypted value => key, string, it is the key Postconditions => If both encrypted_attribute and key are present * Returns decrypted value - string => Else * Returns nil



48
49
50
51
52
# File 'lib/encryptor.rb', line 48

def decrypt(encrypted_attribute, key)
  if encrypted_attribute.present? and key.present?
    AES.decrypt(encrypted_attribute, key)
  end
end

#encrypt(attribute) ⇒ Object

Preconditions => attribute - string, it is the unencrypted value Postconditions => If attribute is present * Returns a hash with the following keys: - key - string - encrypted_attribute - string => Else * Returns a hash with the same keys as above but with nil values



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/encryptor.rb', line 63

def encrypt(attribute)
  if attribute.present?
    key = AES.key

    encrypted_attribute = AES.encrypt(attribute, key)
  end

  {
    key: key,
    encrypted_attribute: encrypted_attribute
  }
end