【发布时间】:2020-05-09 00:53:48
【问题描述】:
我正在使用 crypto-js 在 React Native 中进行哈希处理。
我有一些代码使用不同的库,可以使用 Ed25519 密钥对字符串或二进制数据进行签名。
我正在尝试将crypto-js SHA256 哈希转换为UTF-8 字符串,以便我可以将它与库一起使用。但是,它一直说Malformed UTF-8 data
我不确定我是否根本无法将其转换为 UTF-8?这很奇怪,因为我已经能够成功地使用 Node 的加密模块来做到这一点 - 只是无法使用 crypto-js
这是我的代码:https://repl.it/repls/CornsilkPlasticSpof
另外,在此处添加以防止链接死亡,
const CryptoJS = require("crypto-js");
const dataToBeHashed = "testing";
const toBeSigned = CryptoJS.SHA256(dataToBeHashed).toString(CryptoJS.enc.Utf8);
console.log(toBeSigned);
这给了
Error: Malformed UTF-8 data
at Object.stringify (/home/runner/CornsilkPlasticSpof/node_modules/crypto-js/core.js:513:24)
at WordArray.init.toString (/home/runner/CornsilkPlasticSpof/node_modules/crypto-js/core.js:268:38)
at /home/runner/CornsilkPlasticSpof/index.js:5:52
at Script.runInContext (vm.js:131:20)
at Object.<anonymous> (/run_dir/interp.js:156:20)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:
【问题讨论】:
标签: react-native cryptography cryptojs