annety
annety

Reputation: 35

How to use SHA256 in NodeJS

How to simplely convert a string to SHA256 string in Node.js. And convert a SHA256 string to a normal string?

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

Where should i put the HASH CODE?

Upvotes: 0

Views: 3153

Answers (1)

agtabesh
agtabesh

Reputation: 568

SHA256 is a one-way hash function which means you can only convert a string into a hash value not its reverse. To check password, you need to rehash plain password and compare it with the one you already stored in database.

Upvotes: 1

Related Questions