admin管理员组

文章数量:1336380

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

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

Share Improve this question asked Aug 18, 2016 at 11:49 user6730596user6730596 5
  • Hi m03a3a17, and wele to Stack Overflow. If you are getting an error when you run your code, then you need to show that error in your question; otherwise it is very difficult for anybody to know exactly what is going wrong. – Vince Bowdren Commented Aug 18, 2016 at 12:03
  • okay man... thanks.. i will try it next time.... btw do you think i asked good question – user6730596 Commented Aug 18, 2016 at 12:11
  • 1 AES is an encryption algorithm (reversible) and not a hash function (non-reversible). Please don't confuse them. Passwords must be hashed, but a single hash isn't enough, because attackers have fast password hashing machines. You need to hash it repeatedly. Functions for this is something like PBKDF2 which is supported by CryptoJS. Since hash functions are one-way function, you won't be able to "decrypt" the hashes. In order to authenticate your user, you can run the password through the hash function again in order to pare with the hash that is stored in the database. – Artjom B. Commented Aug 18, 2016 at 18:36
  • See more: How to securely hash passwords? – Artjom B. Commented Aug 18, 2016 at 18:37
  • thanks very much.. you almost clear me the concept – user6730596 Commented Aug 18, 2016 at 21:45
Add a ment  | 

1 Answer 1

Reset to default 8

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());

本文标签: javascripthow to store CryptoJS encrypted password in databaseStack Overflow