Module: PreciousCargo::Data
- Defined in:
- lib/precious_cargo/data.rb
Overview
Public: A collection of methods to encrypt and decrypt data using a supplied secret.
Class Method Summary collapse
-
.decrypt!(encrypted_data, options = {}) ⇒ Object
Public: Decrypt the supplied data using a secret string.
-
.encrypt!(data, options = {}) ⇒ Object
Public: Encrypt the supplied data using a secret string.
Class Method Details
.decrypt!(encrypted_data, options = {}) ⇒ Object
Public: Decrypt the supplied data using a secret string. Currently only supports AES 256 encryption. data - The data to be encrypted. options - Hash of values used to encrypt the secret.
:secret - A secret string.
Returns the AES encrypted data.
26 27 28 29 30 |
# File 'lib/precious_cargo/data.rb', line 26 def decrypt!(encrypted_data, = {}) secret = [:secret] cipher = Gibberish::AES.new(secret) cipher.decrypt(encrypted_data).strip end |
.encrypt!(data, options = {}) ⇒ Object
Public: Encrypt the supplied data using a secret string. Currently only supports AES 256 encryption. data - The data to be encrypted. options - Hash of values used to encrypt the secret.
:secret - A secret string.
Returns the AES encrypted data.
14 15 16 17 18 |
# File 'lib/precious_cargo/data.rb', line 14 def encrypt!(data, = {}) secret = [:secret] cipher = Gibberish::AES.new(secret) cipher.encrypt(data) end |