node.js hash string?

后端 未结 11 2374
暗喜
暗喜 2020-12-02 03:49

I have a string that I want to hash. What\'s the easiest way to generate the hash in node.js?

The hash is for versioning, not security.

11条回答
  •  甜味超标
    2020-12-02 04:31

    Simple One Liners:

    If you want UTF8 text hash:

    const hash = require('crypto').createHash('sha256').update('Hash me', 'utf8').digest('hex');
    

    If you want to get the same hash with Python, PHP, Perl, Github:

    const hash = require('crypto').createHash('sha256').update('Hash me', 'binary').digest('hex');
    

    You can also replace 'sha256' with 'sha1', 'md5', 'sha256', 'sha512'

提交回复
热议问题