如何将这个mcrypt php代码转换成nodejs中的相同代码?

我需要改变这个PHP代码:

$cipher_alg = MCRYPT_TRIPLEDES; $key = "thekey"; $iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg, MCRYPT_MODE_ECB), MCRYPT_RAND); $encrypted_string = mcrypt_encrypt($cipher_alg, $key, $string, MCRYPT_MODE_ECB, $iv); return base64_encode($encrypted_string); 

到nodejs。

我使用https://github.com/tugrul/node-mcrypt进行testing,但使用相同的string,encryption结果不一样:

代码nodejstesting:

 let blowfishCfb = new MCrypt('tripledes', 'ecb'); let iv = blowfishCfb.generateIv(); blowfishCfb.validateKeySize(false); blowfishCfb.validateIvSize(false); blowfishCfb.open('thekey', iv); let ciphertext = blowfishCfb.encrypt(text); return Buffer.concat([iv, ciphertext]).toString('base64'); 

你能帮助理解这个吗?

谢谢,

不要连接IV和密码:

 let blowfishCfb = new MCrypt('tripledes', 'ecb'); let iv = blowfishCfb.generateIv(); blowfishCfb.validateKeySize(false); blowfishCfb.validateIvSize(false); blowfishCfb.open('thekey', iv); let ciphertext = blowfishCfb.encrypt(text); return ciphertext.toString('base64');