I have text encoded using Blowfish using PHP mcrypt:
$td = mcrypt_module_open ('blowfish', '', 'cfb', ''); $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND); mcrypt_generic_init ($td, "somekey", $iv); $crypttext = mcrypt_generic ($td, "sometext"); mcrypt_generic_deinit ($td); $res = base64_encode($iv.$crypttext);
When I try to decode data using the Node crypto library, I get garbage output.
var crypto = require("crypto"), ivAndCiphertext = "base64-encoded-ciphertext", iv, cipherText, ivSize = 8, res= ""; ivAndCiphertext = new Buffer(ivAndCiphertext, 'base64'); iv = new Buffer(ivSize); cipherText = new Buffer(ivAndCiphertext.length - ivSize); ivAndCiphertext.copy(iv, 0, 0, ivSize); ivAndCiphertext.copy(cipherText, 0, ivSize); c = crypto.createDecipheriv('bf-cfb', "somekey", iv.toString("binary")); res = c.update(cipherText, "binary", 'utf8'); res += c.final('utf8');
Any idea on what I'm doing wrong?
EDIT
Using openssl (which the crypto library is a wrapper for) directly gives the same distorted result:
openssl enc -K the_key_in_hex bf-cfb -d -p -iv the_iv_in_hex -nosalt -nopad -a
So this is not like a problem with Javascript code.