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

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

报告相同问题?