Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement SHA-256 encryption in Angular2

I need to encrypt my password in SHA256 before making API request . I am not able to find any implementation of SHA-256 in Angular2

like image 652
Shifs Avatar asked May 10 '17 13:05

Shifs


People also ask

Can you encrypt with sha256?

SHA-256 is a patented cryptographic hash function that outputs a value that is 256 bits long. What is hashing? In encryption, data is transformed into a secure format that is unreadable unless the recipient has a key. In its encrypted form, the data may be of unlimited size, often just as long as when unencrypted.

How many number of steps Sha 256 requires?

Explanation: The number of round computation steps in the SHA-256 algorithm is 64.

Does SHA 256 require a key?

Hash functions like SHA-* do not need a key, they just calculate a hash-value from any input.


1 Answers

I used sha.js for this purpose, it is so simple and does the trick!

First npm install --save sha.js

Import in your component, service, etc... :

import * as shajs from 'sha.js';

And then use it as the docs suggests:

shajs('sha256').update({stringToBeHashed}).digest('hex')
like image 99
hmartos Avatar answered Sep 18 '22 20:09

hmartos