如何将这个mcrypt php代码转换为nodejs中的相同代码?
我需要转换此php代码:如何将这个mcrypt php代码转换为nodejs中的相同代码?,php,node.js,mcrypt,Php,Node.js,Mcrypt,我需要转换此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_
$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);
点头
我使用相同的字符串进行了测试,但加密结果不同:
已测试的代码节点:
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');
不要将IV和cypher连接在一起:
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');
哇,四个糟糕的安全选择组合:三重DES、ECB模式、河豚和空填充!还要注意,ECB模式没有使用IV.Wow,这是四种糟糕的安全选项的组合:三重DES、ECB模式、河豚和空填充!还要注意,ECB模式不使用IV。ECB模式不使用IV,因此创建IV没有意义。ECB模式不使用IV,因此创建IV没有意义。