gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 02:04:34 26 4
gpt4 key购买 nike

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com