Skip to content

Instantly share code, notes, and snippets.

@fabiomcosta
Created April 5, 2011 04:17
Show Gist options
  • Save fabiomcosta/903024 to your computer and use it in GitHub Desktop.
Save fabiomcosta/903024 to your computer and use it in GitHub Desktop.
var crypto = require("crypto");
var repeat = function(str, times){
var _str = str;
while(--times){
str += _str;
}
return str;
};
var cipher = crypto.createCipher("aes-128-ecb", repeat("1", 16));
// changing to "ascii" or "binary" will give the same result
console.log(cipher.update(repeat("2", 16), "utf8", "base64")); // prints K5GLLZeXr3ufthAEFTTe
import base64
from Crypto.Cipher import AES
cypher = AES.new("1" * 16)
print base64.b64encode(cypher.encrypt("2" * 16)) # prints MoiphN0G/1jpOWCx3sUPHg==
require 'openssl'
require 'base64'
c = OpenSSL::Cipher::Cipher.new("aes-128-ecb")
c.encrypt
c.key = "1" * 16
e = c.update("2" * 16)
e = Base64.encode64(e)
puts e # prints MoiphN0G/1jpOWCx3sUPHg==
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment