为了账号安全,请及时绑定邮箱和手机立即绑定

如何将Uint8数组的对象转换为字符串?

如何将Uint8数组的对象转换为字符串?

慕容708150 2022-09-29 10:49:26
我有与这个问题相同的问题。我看到了答案,但我不明白我该怎么做。还有其他建议吗?我的代码是: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()); });当我使用变量时,我有这个错误:actualUncaught (in promise) Error: Bad public key这是加密的输出:这是编码的输出:而这输出的实际“有些事情我想是变化的,不是吗?”:
查看完整描述

2 回答

?
慕森卡

TA贡献1806条经验 获得超8个赞

解析时,您需要发送齐磊函数,该函数有条件地解析对象。如果您看到编码的外观,您将了解为什么需要以这种方式编写reviver函数。

//img1.sycdn.imooc.com//6335464f000136cb06360228.jpg

查看完整回答
反对 回复 2022-09-29
?
小怪兽爱吃肉

TA贡献1852条经验 获得超1个赞

我认为您需要从中删除“十六进制”编码参数。Buffer.from



查看完整回答
反对 回复 2022-09-29
  • 2 回答
  • 0 关注
  • 183 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号