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

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

报告相同问题?

悬赏问题

  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏