Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

411
Vistas
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 Respuestas
Responde la pregunta

0

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

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

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

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

about 4 years ago · Santiago Trujillo Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda