PHP 中的
md5
:
md5 ( string $str [, bool $raw_output = false ] )
If the optional raw_output is set to TRUE, then the md5 digest is instead returned in raw binary format with a length of 16.
所以你可以在 php 中执行以下操作:
$ php -a
>>> md5('data', true)
=> b"ìw\x7F8]=■╚ü] ¸I`&▄"
我尝试在nodejs中使用加密:
$ node
>>> crypto.createHash('md5').update('data').digest('binary')
'w8]=þÈ] ÷I`&Ü'
但结果不一样
我想在nodejs中使用raw_output选项加密数据,如何实现?
最佳答案
您将编码设置为“二进制”,改为使用“十六进制”
crypto.createHash('md5').update('data').digest('hex')
https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding
关于php - Nodejs md5 与 raw_output 就像 php 中的 md5(data, raw_output),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44792961/