Node.js 不能使用加密作为函数

问题描述 投票:0回答:1
const { hashGen } = require('crypto');

var hash = hashGen('sha256').update(hash).digest('hex');

我收到错误: 类型错误:hashGen 不是函数

我尝试创建一个前面有盐的密码,然后使用 SHA-256 对其进行哈希处理,但我在运行时收到错误。

javascript node.js cryptography
1个回答
0
投票

我认为你写的函数是错误的

您可以使用以下方式创建:

const hash = crypto.createHash('sha256', secret)

https://www.geeksforgeeks.org/node-js-crypto-createhash-method/

如果你想创建密码哈希,请尝试 Bcrypt,sha256 很安全,但它是一个快速哈希,并非不可能发现,现有数据库(包含大量哈希和你的内容)

© www.soinside.com 2019 - 2024. All rights reserved.