use*_*947 6 javascript hash hmac node.js
我正在将一个php脚本移植到节点,我对加密知之甚少.
php脚本使用此功能:
hash_hmac('sha512', text, key);
Run Code Online (Sandbox Code Playgroud)
所以,我需要在Node js中实现一个函数,用于使用hmac方法(SHA512)返回一个键控哈希.
从我所看到的,node通过crypto模块内置了这个功能(http://nodejs.org/docs/latest/api/crypto.html#crypto_crypto) - 但是我不清楚如何重现这个功能.
任何帮助,将不胜感激.
谢谢,
是的,使用加密库.
var hash = crypto.createHmac('sha512', key);
hash.update(text);
var hashed_data = hash.digest();
Run Code Online (Sandbox Code Playgroud)
更多详细信息(例如,用于控制输出编码的摘要参数hash.digest)位于您提供的链接中.
正如Nick指出的那样,每次要加密新字符串时都需要执行整个过程(即hash通过创建新对象crypto.createHmac).
| 归档时间: |
|
| 查看次数: |
3425 次 |
| 最近记录: |