【关键字】
Uint8Array / @ohos.buffer / HEX
【问题描述】
RSA加解密过程中,从Cipher.doFinal中获取的DataBlob.data为Uint8Array,需要转换后传给后台进行校验。
如何将Uint8Array数组转换为HEX编码后的String输出,类似于Java中的Hex.encode(byte [] bytes)?
【解决方案】
可以通过@ohos.buffer进行转换:
let uint8Arr = new Uint8Array(buffer.from('Hello World!').buffer)
let str = buffer.from(uint8Arr.buffer).toString('hex')
参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-buffer-0000001774121090