php - Nodejs md5 与 raw_output 就像 php 中的 md5(data, raw_output)

标签 php node.js

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/

相关文章:

node.js - 如何将文件上传到Cloudinary中的某个文件夹? Node JS

php - 通过 PHP 中的提交输入显示数组值

php - 从表中随机获取多行

php - [PHP][MySQL] 如何同时向2个表插入数据?

javascript - 让 sails.js 监听远程连接

javascript - NodeJs,connection.query 中的 if 语句

php - 带有 Passport : Get Current User with Personal Access Token 的 Laravel 5.3

php - 我的查询哪里出了问题?

node.js - 如何限制刷新 token 的使用时间为 1 小时

node.js - Passport Facebook 验证未调用回调