![碎片时间学编程「93]:元素计算 SHA-256 哈希 (Node.js)](https://p6.toutiaoimg.com/origin/tos-cn-i-qvj2lq49k0/8bfb45b97fe6490791486ebeafe3efbd.png?from=pc)
使用SHA-256算法为值创建哈希。返回一个 Promise。
JavaScript
const crypto = require('crypto');
const hashNode = val =>
new Promise(resolve =>
setTimeout(
() => resolve(crypto.createHash('sha256').update(val).digest('hex')),
0
)
);示例:
hashNode(JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })).then(
console.log
);
// '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393'更多内容请访问我的网站:https://www.icoderoad.com
| 留言与评论(共有 0 条评论) “” |