angel angel - 1 year ago 197
Node.js Question

Decrypt error using simplecrypt

I am new to nodejs,sails and need to encrypt some data before storing it in the database.

I have found the module simplecrypt

And have made this code demo.

var simplecrypt = require("simplecrypt");

var sc = simplecrypt();
var digest = sc.encrypt("my secret");
console.log(digest); // "66cea6eb1c18b8862485cf0604fa6062"

var message = sc.decrypt(digest);
console.log(message); // "my secret"

It does encrypt the value, but when I attempt to decrypt I get an error:

var ret =;
Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
at Error (native)
at (crypto.js:202:26)

Can someone suggest a way for me to correctly decrypt my encrypted value?

Answer Source

After spend all day for checking, I foud out the result. I have to define

var user1 ={

and assign values get from mydabase to user1 and declare

 var sc = simplecrypt(user1);
 var passEncrypt = sc.encrypt(passworduserinput);

then compare user.password with passEncrypt.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download