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
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.
Explanation: The number of round computation steps in the SHA-256 algorithm is 64.
Hash functions like SHA-* do not need a key, they just calculate a hash-value from any input.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With