亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將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函數。

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

查看完整回答
反對 回復 2022-09-29
?
小怪獸愛吃肉

TA貢獻1852條經驗 獲得超1個贊

我認為您需要從中刪除“十六進制”編碼參數。Buffer.from



查看完整回答
反對 回復 2022-09-29
  • 2 回答
  • 0 關注
  • 174 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號