【发布时间】:2018-03-30 02:22:43
【问题描述】:
我需要转换这个 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 进行了测试,但使用相同的字符串,加密的结果不一样:
代码 nodejs 测试:
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');
你能帮忙理解一下吗?
谢谢,
【问题讨论】:
-
哇,四种糟糕的安全选择的组合:三重 DES、ECB 模式、Blowfish 和空填充!另请注意,ECB 模式不使用 IV。