HarmonyOS TLSSocket的二进制转成字符串的转换方法

现有TLSSocket无法支持二进制,强制发送字符串,但是我们业务只能获取到二进制,因此需要使用二进制转换成字符串的方法,我们尝试了两种转换

let   byteArray: Uint8Array = new Uint8Array([0x82,0x00,0x00,0x82,0x34,0x3d,0x30,0x00,0x31,0x31,0x3d,0x35,0x30,0x39,0x00,0x35,0x3d,0x33,0x32,0x00,0x31,0x3d,0x31,0x30,0x34,0x00,0x36,0x39,0x3d,0x63,0x6c,0x69,0x65,0x6e,0x74,0x55,0x6e,0x69,0x71,0x75,0x65,0x3d,0x30,0x45,0x39,0x44,0x38,0x33,0x35,0x34,0x2d,0x41,0x37,0x36,0x38,0x2d,0x34,0x45,0x44,0x46,0x2d,0x39,0x46,0x42,0x39,0x2d,0x36,0x38,0x39,0x34,0x43,0x39,0x39,0x30,0x31,0x35,0x32,0x43,0x00,0x63,0x6c,0x69,0x65,0x6e,0x74,0x54,0x79,0x70,0x65,0x3d,0x49,0x70,0x68,0x00,0x63,0x6c,0x69,0x65,0x6e,0x74,0x56,0x65,0x72,0x73,0x69,0x6f,0x6e,0x3d,0x38,0x2e,0x33,0x33,0x2e,0x39,0x39,0x2e,0x31,0x00,0x6d,0x61,0x72,0x6b,0x69,0x64,0x3d,0x75,0x6e,0x6b,0x6e,0x6f,0x77,0x6e,0x00,0x00])

let bufferStr = buffer.from(byteArray.buffer).toString();


const decoder = util.TextDecoder.create();
let bufferStr2 = decoder.decodeWithStream(byteArray,{stream:true})

发现发送出去的字节均和初始bytearray内的字节不一致,请问应该怎么转换

HarmonyOS
7天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect
分享
微博
QQ
微信
回复
7天前
相关问题
HarmonyOS进制二进制方法
170浏览 • 1回复 待解决
HarmonyOS 二进制转16进制
151浏览 • 1回复 待解决
HarmonyOS 摘要数据转换16进制字符串
60浏览 • 1回复 待解决
如何对二进制进行AES解密?
363浏览 • 1回复 待解决
如何直接加载二进制图片?
2908浏览 • 1回复 待解决
jsbind--二进制包导入指导
886浏览 • 1回复 待解决
native层如何访问rawfile二进制文件
1976浏览 • 1回复 待解决
base目录内容会被编译成二进制
104浏览 • 1回复 待解决
HarmonyOS gzip二进制流压缩和解压缩
945浏览 • 1回复 待解决
HarmonyOS将对象转换字符串方法
726浏览 • 1回复 待解决
ResourceStr 类型如何转成字符串
386浏览 • 1回复 待解决
转换整个字符串字符为小写
408浏览 • 1回复 待解决
HarmonyOS 十六进制字符转明文字符串
242浏览 • 1回复 待解决