Class: Cript::Simple
Overview
Cript::Simple is a simple ruby wrapper around RSA SSH keys and a blowfish cipher. It allows you to easily encrypt and decrypt strings.
Instance Method Summary collapse
Methods inherited from Cripter
Constructor Details
This class inherits a constructor from Cript::Cripter
Instance Method Details
#decrypt(message) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/cript/simple.rb', line 21 def decrypt() encrypted_key, iv, = Marshal.load(Base64::decode64()) key = @private_key.private_decrypt(encrypted_key) cipher = OpenSSL::Cipher::Cipher.new('bf-cbc').decrypt cipher.key = key cipher.iv = iv cipher.update() + cipher.final end |
#encrypt(message) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/cript/simple.rb', line 12 def encrypt() cipher = OpenSSL::Cipher::Cipher.new('bf-cbc').encrypt key = cipher.random_key iv = cipher.random_iv = cipher.update() + cipher.final encrypted_key = @public_key.public_encrypt(key) Base64::encode64(Marshal.dump([encrypted_key,iv,])) end |