如何在数据库中存储CryptoJS加密密码

how to store CryptoJS encrypted password in database

本文关键字:CryptoJS 加密 密码 存储 数据库      更新时间:2023-09-26

我对CRYPTO JS加密的东西很陌生,我试图在数据库中存储加密的哈希(我试图存储在firebase数据库中)。

    var hash = CryptoJS.AES.encrypt('my message', 'secret key 123');

我试图在数据库中存储哈希变量。但是当我试图存储时,它向我显示错误,它是函数,不可能存储。

PS-我试图在数据库中存储加密哈希,并希望从数据库中调用应用程序的另一页上的加密哈希,并在那里解密。

这可能吗?如果是,请告诉我怎么做。由于

您的hash是一个对象,您需要调用hash.toString()将其转换为字符串。

从CryptoJS github页面:

var hash = CryptoJS.SHA3("Message");
//The hash you get back isn't a string yet. It's a WordArray object.
//When you use a WordArray object in a string context,
//it's automatically converted to a hex string. 
alert(hash.toString()); //Same as hash.toString(CryptoJS.enc.Hex);
// Import and use instance for TypeScript.
import * as crypto from "crypto-js";
console.log(crypto.SHA256("password").toString());