dongyuluan7494 2017-06-28 03:04
浏览 121
已采纳

nodejs md5,其中raw_output与php中的md5(data,raw_output)类似

md5 in php:

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.

so you can do this following in php:

$ php -a
>>> md5('data', true)
=> b"ìw\x7F8]=■╚ü] ¸I`&▄"

I was tried using crypto in nodejs:

$ node
>>> crypto.createHash('md5').update('data').digest('binary')
'w8]=þÈ] ÷I`&Ü'

But the result not same

I want to encrypt data with raw_output option in nodejs, how to achieve it?

  • 写回答

1条回答 默认 最新

  • doutongya8378 2017-06-28 03:21
    关注

    You had your encoding as 'binary' use 'hex' instead

    crypto.createHash('md5').update('data').digest('hex')
    

    https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法