Created
March 23, 2014 13:49
-
-
Save thinkclay/9723304 to your computer and use it in GitHub Desktop.
Ruby: AES Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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