Reputation:
i am quite new to CRYPTO JS encrypted stuff and i am trying to store encryted hash in database(I am trying to store in firebase database).
var hash = CryptoJS.AES.encrypt('my message', 'secret key 123');
I am trying to store hash variable in database. But when i am trying to store, it shows me error that it is function, not possible to store.
PS- i am trying to store encryted hash in databse and want to call encrpted hash on another page of my application from database and decrypt there.
Is that possible? if yes, then please tell me how. Thanks
Upvotes: 1
Views: 7035
Reputation: 10782
Your hash
is an object, you need to call hash.toString()
to convert it into a string.
From the CryptoJS github page:
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());
Upvotes: 8