在 React 中使用 crypto-js

Rya*_*yan 5 cryptojs reactjs create-react-app

我使用生成了一个应用程序create-react-app,我想使用 crypto-js 我收到以下错误

crypto.sha256() is not a function

sud*_*ang 9

你必须使用安装crypto-js

npm install crypto-js
Run Code Online (Sandbox Code Playgroud)

在你的 js 文件中,你必须导入你想要使用的模块

import sha256 from 'crypto-js/sha256';
Run Code Online (Sandbox Code Playgroud)

现在你可以使用这些功能

sha256(nonce + message);
Run Code Online (Sandbox Code Playgroud)

你必须做定义message,并nonce在此之前