一个php openssl_encrypt转node写法,无法成功?

下面这段代码在node中要怎么写呢?

$cipher = base64_encode(openssl_encrypt(json_encode($param), 'aes-128-cbc', hash('MD5', $aesKey, true), OPENSSL_RAW_DATA, $iv));

我的代码是这样的,但是发现结果并不一样。。。。

const hash = crypto.createHash( 'MD5' )
hash.update( aesKey )
const aesKeySignStr = hash.digest()
const iv = Math.random().toString( 36 ).substr( 2 )

const cipher = crypto.createCipher( 'aes-128-cbc', aesKeySignStr, iv )
console.log( JSON.stringify( this.params ) );
let crypted = cipher.update( JSON.stringify( this.params ), 'utf8', 'hex' )
crypted += cipher.final( 'hex' )

请各位大佬搭救。

阅读 2.1k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题