我需要使用私钥从字符串创建 HmacSHA256...
我使用react-native-crypto-js,但我不能使用它的HmacSHA256方法,
它不断出现“未定义函数”错误,这是我的代码:
const signature = CryptoJS.HmacSHA256('simple', '123456789');
const signatureBase = signature.toString(CryptoJS.enc.Base64);
我遵循了它的文档,但仍然遇到相同的错误,
如果您知道其他解决方案或使用此软件包的正确方法,请帮助我。
谢谢。
我找到了解决方法反应本机 Windows HmacSHA256算法。我用过2个包
Step 1:
npm install --save react-native-hash //install this
import { JSHash, JSHmac, CONSTANTS } from "react-native-hash";
JSHmac("message", "SecretKey", CONSTANTS.HmacAlgorithms.HmacSHA256)
.then(hash => hmac_encoded_str=hash)
.catch(e => console.log(e));
OR
let hmac_encoded_str= await JSHmac(canonical_string, "C6PqJwbyW4",
CONSTANTS.HmacAlgorithms.HmacSHA256)
Step 2:
npm install react-native-crypto-js // install this as well
import CryptoJS from "react-native-crypto-js"
CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(hmac_encoded_str));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)