Skip to content

Instantly share code, notes, and snippets.

@thinkclay
Created March 23, 2014 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkclay/9723304 to your computer and use it in GitHub Desktop.
Save thinkclay/9723304 to your computer and use it in GitHub Desktop.
Ruby: AES Example
require 'uri'
require 'net/http'
require 'net/https'
require 'base64'
input = "this is a test"
iv = "532b6195636c6127"
key = "532b6195636c61279a010000"
puts "Input: [" + input.bytes.join(" ") + "]"
puts "Key: [" + key.bytes.join(" ") + "]"
puts "IV: [" + iv.bytes.join(" ") + "]"
cipher = OpenSSL::Cipher::AES.new(128, :CFB)
cipher.encrypt
cipher.key = key
cipher.iv = iv
encrypted = cipher.update(input)
decipher = OpenSSL::Cipher::AES.new(128, :CFB)
decipher.decrypt
decipher.key = key
decipher.iv = iv
puts "Output: [" + encrypted.bytes.join(" ") + "]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment