How to use 'crypto' module in Angular2?

前端 未结 4 680
无人及你
无人及你 2020-12-06 02:27

I install module:

npm install --save crypto

I import it to my component:

import { createHmac } from \"crypto\";
         


        
4条回答
  •  一向
    一向 (楼主)
    2020-12-06 03:03

    I am developing with the latest versions of Angular and 'crypto-js' seems to work fine.

    Install the package and the definitions:

    npm install crypto-js
    npm install --save @types/crypto-js
    

    Use it:

    import { SHA256, enc } from "crypto-js";
    ...
    login() {
    ...
       const hashedPass = SHA256(this.loginForm.value.password).toString(enc.Hex);
    ...
    }
    

提交回复
热议问题