Class: Ripple::Encryption::Encryptor
- Inherits:
-
Object
- Object
- Ripple::Encryption::Encryptor
- Defined in:
- lib/ripple-encryption/encryptor.rb
Overview
Implements a simple object that can either encrypt or decrypt arbitrary data.
Example usage:
encryptor = Ripple::Encryption::Encryptor.new Ripple::Encryption::Config.defaults
encryptor.encrypt stuff
encryptor.decrypt stuff
Instance Method Summary collapse
-
#decrypt(blob) ⇒ Object
Decrypt stuff.
-
#encrypt(blob) ⇒ Object
Encrypt stuff.
-
#initialize(config) ⇒ Encryptor
constructor
Creates an Encryptor that is prepared to encrypt/decrypt a blob.
Constructor Details
#initialize(config) ⇒ Encryptor
Creates an Encryptor that is prepared to encrypt/decrypt a blob.
12 13 14 15 16 17 18 19 |
# File 'lib/ripple-encryption/encryptor.rb', line 12 def initialize(config) # ensure that we have the required configuration keys %w(cipher key iv).each do |option| raise(Ripple::Encryption::EncryptorConfigError, "Missing configuration option '#{option}'.") if config[option].nil? end @config = config @cipher = OpenSSL::Cipher.new(@config['cipher']) end |
Instance Method Details
#decrypt(blob) ⇒ Object
Decrypt stuff.
30 31 32 33 |
# File 'lib/ripple-encryption/encryptor.rb', line 30 def decrypt(blob) initialize_cipher_for :decrypt "#{@cipher.update blob}#{@cipher.final}" end |
#encrypt(blob) ⇒ Object
Encrypt stuff.
23 24 25 26 |
# File 'lib/ripple-encryption/encryptor.rb', line 23 def encrypt(blob) initialize_cipher_for :encrypt "#{@cipher.update blob}#{@cipher.final}" end |