Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

758
Views
How to use 'crypto' module in Angular2?

I install module:

npm install --save crypto

I import it to my component:

import { createHmac } from "crypto";

But I get error:

ERROR in -------------- (4,28): Canno t find module 'crypto'.

What am I doing wrong?

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

To use the NodeJS crypto library with Typescript (Angular >= 2, for example), follow these steps:

  1. npm install @types/node --save-dev to install NodeJS definitions
  2. In the tsconfig.ts file add the following:

    "files": [ "./node_modules/@types/node/index.d.ts" ]

  3. Import the library wherever you want to use it with import * as crypto from 'crypto';

about 4 years ago · Santiago Trujillo Report

0

You need to install the definition files for a 3rd party library like crypto. So that typescript can find the "meaning" for it.

I think the definition file is:

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

Then you can import the module like:

import * as crypto from "crypto";

If you can't find the definition file for that lib, you can write it on your own or as a workaround you can declare the module as any but typescript won't be able to auto-complete the methods.

declare var crypto: any;

and use its methods like:

crypto.createHmac..
about 4 years ago · Santiago Trujillo Report

0

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);
...
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!