【发布时间】:2017-02-12 11:32:38
【问题描述】:
我有这个用于加密数据的 php 函数,如何将其转换为 NodeJS?
<?php
function Encrypt($input, $key_seed){
$input = trim($input);
$block = mcrypt_get_block_size('tripledes', 'ecb');
$len = strlen($input);
$padding = $block - ($len % $block);
$input .= str_repeat(chr($padding),$padding);
// generate a 24 byte key from the md5 of the seed
$key = substr(md5($key_seed),0,24);
$iv_size = mcrypt_get_iv_size(MCRYPT_TRIPLEDES, MCRYPT_MODE_ECB);
echo "--" . $iv_size . "\n";
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
// encrypt
$encrypted_data = mcrypt_encrypt(MCRYPT_TRIPLEDES, $key,
$input, MCRYPT_MODE_ECB, $iv);
// clean up output and return base64 encoded
return base64_encode($encrypted_data);
}
请帮帮我!谢谢!
【问题讨论】:
标签: php node.js encryption