javascript - 如何将 Uint8Array 的对象转换为字符串?
问题描述
我和这个问题有同样的问题。我看到了答案,但我不明白我该怎么做。还有其他建议吗?
我的代码是:
var eccrypto = require("eccrypto");
var w,actual;
var publicKey = Buffer.from([4, 86, 82, 58, 244, 11, 140, 41, 132, 245, 184, 162, 163, 98, 49, 119, 168, 235, 252, 50, 6, 91, 147, 191, 190, 61, 65, 63, 101, 164, 132, 213, 188, 106, 26, 203, 171, 215, 240, 151, 7, 193, 10, 151, 103, 107, 1, 135, 117, 225, 5, 41, 55, 57, 18, 205, 98, 178, 82, 135, 170, 111, 188, 98, 57],'hex');
var privateKey= Buffer.from([238, 239, 199, 101, 188, 134, 13, 13, 195, 172, 125, 168, 225, 189, 72, 148, 225, 200, 127, 218, 204, 11, 150, 146, 180, 243, 195, 109, 200, 119, 50, 20],'hex');
eccrypto.encrypt(publicKey, Buffer.from("message")).then(function(encrypted) {
console.log(encrypted)
let encoded =JSON.stringify(encrypted)
w=encoded;
console.log(encoded)
actual = JSON.parse((encoded))
console.log(actual)
});
eccrypto.decrypt(privateKey,actual).then(function(plaintext) {
console.log("Message to part B:", plaintext.toString());
});
当我使用actual
变量时,我有这个错误:
Uncaught (in promise) Error: Bad public key
这是 encrypted 的输出:
这是编码的输出:
解决方案
推荐阅读
- flutter - Gridview 在颤动中不可见
- angular - 角度对话框未作为模式窗口打开
- javascript - 我应该使用什么搜索例程来匹配我的 HTML 表的确切条目?
- android - Zxing 在某些设备中不显示摄像头
- java - How to intersect polygon layer with my current GPS in android GIS sdk 100.2.1
- powershell - 如何将哈希表中的数组导出为 CSV?
- php - yii2 mpdf,不显示谷歌地图静态卫星视图
- sql - 如何确定多个日期值的模式以及当有多个模式时该怎么做
- c++ - 如何在静态函数中使用成员函数数组?
- javascript - 在 fullpage.js 中自动播放或滚动幻灯片