Reputation: 9466
For reference, I am using React 16.9.0
and Typescript 3.5.3
.
On this question Are there any SHA-256 javascript implementations that are generally considered trustworthy?, I learned about the forge
node application to create 256 hashes from strings.
Here, you can find the implementation and usage of the sha256 function:
However, I cannot manage to import it on my create-react-app
project with Typescript.
I installed the forge
library with these commands:
npm install node-forge
npm install @types/node-forge
And when I try to import it, Typescript keeps telling me:
TypeScript error in /src/App.tsx(2,10):
Module '"node-forge"' has no exported member 'forge'. TS2305
1 | import React from 'react';
> 2 | import { forge } from 'node-forge';
| ^
3 | import './App.css';
4 |
How can I correctly import the forge hash library in my create-react-app
project, so I can create a hash with this:
var md = forge.md.sha256.create();
md.update('The quick brown fox jumps over the lazy dog');
console.log(md.digest().toHex());
// output: d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592
Upvotes: 0
Views: 2421
Reputation: 138
What about import forge from 'node-forge'
or import * as forge from "node-forge";
. Or you just use different library. For instance: bcrypt
Upvotes: 1