Reputation: 1553
There is a function crypto.pbkdf2Sync()
in node.js
API and I whant to use it in my Angular2 project.
I tried to import it and use it. Project compiles with no error, but in browser I get an error:
TypeError: webpack_require.i(...) is not a function at createHashSlow (hash.ts:4)
Here is the hash.ts
module:
import { pbkdf2Sync } from 'crypto';
import { CONFIG } from '../config';
export function createHashSlow(password, salt) {
return pbkdf2Sync(
password,
salt,
CONFIG.crypto.hash.iterations,
CONFIG.crypto.hash.length,
'SHA1'
).toString('base64');
};
What did I do wrong? How to make it work?
Upvotes: 0
Views: 1669
Reputation: 39289
The crypto module is based on OpenSSL that is not available in the browser
The crypto module provides cryptographic functionality that includes a set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign and verify functions.
I suggest to use WebCryptographyApi that is available in all modern browsers. See an example here Angular JS Cryptography. pbkdf2 and iteration
Upvotes: 1