I have asmcrypto.js in my react-native app. Whenever I run my app, the build is successful but while running it throws below error:
error: Error: Unable to resolve module crypto from E:\Work\ALL CodeBase\Maptaskr\Maptaskr\node_modules\asmcrypto.js\asmcrypto.all.js: crypto could not be found within the project or in these directories:
node_modules
4247 | function getRandomValues(buf) {
4248 | if (typeof process !== 'undefined') {
> 4249 | var nodeCrypto = require('crypto');
| ^
4250 | var bytes = nodeCrypto.randomBytes(buf.length);
4251 | buf.set(bytes);
4252 | return;
at ModuleResolver.resolveDependency (E:\Work\ALL CodeBase\Maptaskr\Maptaskr\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:178:15)
at DependencyGraph.resolveDependency (E:\Work\ALL CodeBase\Maptaskr\Maptaskr\node_modules\metro\src\node-haste\DependencyGraph.js:264:43)
at Object.resolve (E:\Work\ALL CodeBase\Maptaskr\Maptaskr\node_modules\metro\src\lib\transformHelpers.js:170:21)
at resolveDependencies (E:\Work\ALL CodeBase\Maptaskr\Maptaskr\node_modules\metro\src\DeltaBundler\graphOperations.js:466:33)
at processModule (E:\Work\ALL CodeBase\Maptaskr\Maptaskr\node_modules\metro\src\DeltaBundler\graphOperations.js:232:31)
at async addDependency (E:\Work\ALL CodeBase\Maptaskr\Maptaskr\node_modules\metro\src\DeltaBundler\graphOperations.js:361:18)
at async Promise.all (index 8)
at async processModule (E:\Work\ALL CodeBase\Maptaskr\Maptaskr\node_modules\metro\src\DeltaBundler\graphOperations.js:279:3)
at async addDependency (E:\Work\ALL CodeBase\Maptaskr\Maptaskr\node_modules\metro\src\DeltaBundler\graphOperations.js:361:18)
at async Promise.all (index 48)
Can anyone point out what I am doing wrong here?
Usage of asmcrypto.js
:
import React, { Component } from 'react';
import { bindActionCreators } from "redux";
import { connect } from "react-redux";
import AsyncStorage from '@react-native-community/async-storage'
//import {asmcrypto,SHA256} from 'asmcrypto-lite';
import * as asmcrypto from 'asmcrypto.js';
import encoding from 'text-encoding';
import moment from 'moment';
export default class licenseCheck {
async GetHash(input, salt) {
var saltArray = new encoding.TextEncoder("utf-8").encode(salt);
var inputArray = new encoding.TextEncoder("utf-8").encode(input);
var crypted = asmcrypto.Pbkdf2HmacSha256(inputArray, saltArray, 10000, 16)
var base64Converted = asmcrypto.bytes_to_base64(crypted);
//console.log(base64Converted);
return base64Converted;
}
}