Skip to content

Instantly share code, notes, and snippets.

@baudehlo
Created October 3, 2011 20:11
Show Gist options
  • Save baudehlo/1260101 to your computer and use it in GitHub Desktop.
Save baudehlo/1260101 to your computer and use it in GitHub Desktop.
// Input:
// perl -MCrypt::CBC -MMIME::Base64 -le 'print MIME::Base64::encode_base64(Crypt::CBC->new(-key=>"test",-cipher=>"DES",-header=>"randomiv")->encrypt("hello world"))';
var crypto = require ('crypto')
var input = 'UmFuZG9tSVZ2l2agomtNj7G5Rff4byYTKJAMbm4+51M=';
var input_buf = new Buffer(input, 'base64');
var KEY_LENGTH = 8;
var key = new Buffer('test', 'ascii');
var iv = new Buffer(8);
var key_md5 = new Buffer(56);
input_buf.copy(iv, 0, 8, 16);
console.log(input_buf);
console.log(iv);
console.log(key.toString());
console.log(input_buf.slice(16));
var md5sum = crypto.createHash('md5');
md5sum.update(key);
var digest = md5sum.digest();
while (digest.length < KEY_LENGTH) {
md5sum = crypto.createHash('md5');
md5sum.update(digest);
digest += md5sum.digest();
}
digest = digest.substr(0, KEY_LENGTH);
console.log(digest.length);
var decipher = crypto.createDecipheriv('des-cbc', digest, iv.toString('binary'));
var output = decipher.update(input_buf.slice(16), 'binary', 'ascii');
console.log(output);
// output: "hello wo" (WTF?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment