4

I am trying to use node Crypto module in Angular 7 for asymmetric encryption. and used below command to import the Crypto module

import * as crypto from 'crypto';

but still I am getting error that is

`ERROR in src/app/log-in/log-in.component.ts(11,25): error TS2307: Cannot find module 'crypto'.`

Please help me to resolve the error that how to use this library into Angular.

Thanks in Advance.

Jota.Toledo
  • 27,293
  • 11
  • 59
  • 73
VIVEK
  • 257
  • 1
  • 5
  • 18

3 Answers3

8

I was trying to import { randomBytes } from "crypto"; then such error occurred, I installed node types npm install @types/node --save-dev and it was resolved.

Gwamaka Charles
  • 1,479
  • 9
  • 12
2

Per the author on npm , The crypto package is no longer available as it is now built in to Node.js. I would suggest looking for an alternative. I came across a Github Gist that contains some suggestions: https://gist.github.com/jo/8619441

Make sure whatever you pick is useable in the browser. Some of the options listed there are server-side only.

TheHanna
  • 496
  • 5
  • 9
  • 1
    There some Links which are help full in this: node-rsa: https://www.npmjs.com/package/node-rsa Quick-Encrypt: https://www.npmjs.com/package/quick-encrypt asymmetric-crypto: https://www.npmjs.com/package/asymmetric-crypto – VIVEK Feb 08 '19 at 09:40
-3

Make sure that you install 'crypto' module from npm

use: npm i crypto to install this module.

for more information please visit here.

If this is still not working then you have to check for alternative module because this module is dedicated you can check this

Dhaval
  • 868
  • 12
  • 22
  • There is any error while installing module? because this module dedicated you can also use angular-crypto : https://www.npmjs.com/package/angular-crypto – Dhaval Feb 06 '19 at 14:30