Thursday 19 January 2017

Using forge-js in angular 2 for calculating sha256

To use forge-js in angular 2 application for using cryptographic function like sha clone the repository from the git and build the files and include the forge.all.js file in your index.html file
Since the forge-js is not written in typescript and not having the d.ts file. We have to declare the forge and use the functions inside that.
To calculate the sha256 enter the code like.
declare var forge:any;

export class Common{
    getSha256String(value){
      var md = forge.md.sha256.create();
      md.update(value);
      return md.digest().toHex();
    },
}
Now simply call the method getSha256String with the value to get the encrypted value.

No comments:

Post a Comment