Skip to content

Instantly share code, notes, and snippets.

@priithaamer
Created July 28, 2011 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save priithaamer/1111100 to your computer and use it in GitHub Desktop.
Save priithaamer/1111100 to your computer and use it in GitHub Desktop.
Encode/Decode
require 'openssl'
require 'base64'
require 'digest/sha1'
c = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
c.encrypt
# your pass is what is used to encrypt/decrypt
c.key = key = Digest::SHA1.hexdigest("whatever")
# c.iv = iv = c.random_iv
e = c.update("190")
e << c.final
puts "encrypted: #{Base64.encode64(e)}\n"
c = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
c.decrypt
c.key = key
# c.iv = iv
d = c.update(e)
d << c.final
puts "decrypted: #{d}\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment