Skip to content

Instantly share code, notes, and snippets.

@jaz303
Last active December 17, 2015 06:19
Show Gist options
  • Save jaz303/5564695 to your computer and use it in GitHub Desktop.
Save jaz303/5564695 to your computer and use it in GitHub Desktop.
// port of this function:
// https://github.com/openssl/openssl/blob/master/crypto/evp/evp_key.c#L115
var crypto = require('crypto');
var passphrase = new Buffer("secretsecretsecret", "utf8");
var iv = new Buffer("02E2EFAFD7D550A6", "hex");
var addmd = 0;
var md_buf = new Buffer(0);
const KEY_LEN = 24;
var key = new Buffer(KEY_LEN), kpos = 0;
while (kpos < KEY_LEN) {
var hash = crypto.createHash('md5');
if (addmd++) {
hash.update(md_buf);
}
hash.update(passphrase);
hash.update(iv);
md_buf = hash.digest();
var i = 0;
while (kpos < KEY_LEN && i < md_buf.length) {
key[kpos++] = md_buf[i++];
}
}
console.log(key);
console.log(key.length);
var cipher = crypto.createDecipheriv("DES-EDE3-CBC", key, iv);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment