class Cript::Simple

Cript::Simple is a simple ruby wrapper around RSA SSH keys and a blowfish cipher. It allows you to easily encrypt and decrypt strings.

Public Instance Methods

decrypt(message) click to toggle source
# File lib/cript/simple.rb, line 21
def decrypt(message)
  encrypted_key, iv, encrypted_message = Marshal.load(Base64::decode64(message))
  key = @private_key.private_decrypt(encrypted_key)
  cipher = OpenSSL::Cipher::Cipher.new('bf-cbc').decrypt
  cipher.key = key
  cipher.iv = iv
  cipher.update(encrypted_message) + cipher.final
end
encrypt(message) click to toggle source
# File lib/cript/simple.rb, line 12
def encrypt(message)
  cipher = OpenSSL::Cipher::Cipher.new('bf-cbc').encrypt
  key = cipher.random_key
  iv = cipher.random_iv
  encrypted_message = cipher.update(message) + cipher.final
  encrypted_key = @public_key.public_encrypt(key)
  Base64::encode64(Marshal.dump([encrypted_key,iv,encrypted_message]))
end