Skip to content

Instantly share code, notes, and snippets.

@joslynesser
Created February 6, 2012 20:06
Show Gist options
  • Save joslynesser/1754488 to your computer and use it in GitHub Desktop.
Save joslynesser/1754488 to your computer and use it in GitHub Desktop.
require 'openssl'
require 'base64'
key = '7fc4d85e2e4193b8'
crypted_text = Base64.decode64(ARGV[0])
cipher = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
cipher.decrypt
cipher.key = key
decrypted = ""
decrypted << cipher.update(crypted_text)
decrypted << cipher.final
<?php
$key = "7fc4d85e2e4193b8";
$text = "Read me! This is a fun message...";
$iv = "OpenSSL for Ruby";
// Add required padding
$pad = 16 - (strlen($crypttext) % 16);
$text = $text . str_repeat(chr($pad), $pad);
// XOR first block due to ruby's openssl performing this when using the static IV
for ($i = 0; $i < 16; $i++) {
$text[$i] = $text[$i] ^ $iv[$i];
}
$encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv));
print $encrypted ."\n";
?>
require 'openssl'
require 'base64'
key = '7fc4d85e2e4193b8'
crypted_text = Base64.decode64(ARGV[0])
iv = "Random IV Winner"
cipher = OpenSSL::Cipher::Cipher.new("aes-128-cbc")
cipher.decrypt
cipher.key = key
cipher.iv = "OpenSSL NOT Ruby"
decrypted = ""
decrypted << cipher.update(crypted_text)
decrypted << cipher.final
<?php
$key = "7fc4d85e2e4193b8";
$text = "Read me! This is a fun message...";
$iv = "Random IV Winner";
// Add required padding
$pad = 16 - (strlen($crypttext) % 16);
$text = $text . str_repeat(chr($pad), $pad);
$encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $text, MCRYPT_MODE_CBC, $iv));
print $encrypted ."\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment