【发布时间】:2019-07-08 15:12:43
【问题描述】:
如何在 Node.js 中简单地将字符串转换为 SHA256 字符串。 并将 SHA256 字符串转换为普通字符串?
const shajs = require('sha.js');
console.log('starts');
const code = 'WEASDSAEWEWAEAWEAWEWA';
const normal = 'anne';
const encrypted = shajs('sha256')
.update(normal)
.digest('hex');
const unencrypted = shajs('sha256')
.read(normal)
.toString('hex');
console.log(normal);
console.log(encrypted);
console.log(unencrypted);
console.log('end');
我应该把哈希码放在哪里?
【问题讨论】:
-
哈希码是什么意思?
-
你明白SHA256是一种单向哈希吗?您无法将其转换回普通字符串。此外,在 node.js 中,请参阅内置的 nodejs.org/api/crypto.html#crypto_class_hash。
-
在我使用 SHA256 的另一种语言中,我创建了一个哈希码来转换密码 #define HASH_CODE = 'WEASDSAEWEWAEAWEAWEWA'; SHA256_PassHash(inputtext, HASH_CODE, 密码, 64);