【关键字】
字节流 / MD5 / ArrayBuffer
【问题描述】
服务端需要接收字节流参数为MD5格式,所以需要对ArrayBuffer字节流直接进行MD5,不转为字符串。请问如何实现。
【解决方案】
对ArrayBuffer字节流进行MD5可以参考此文档链接。
相关参考代码如下:
const md = cryptoFramework.createMd('SHA256')
// 明文
const message = 'mdTestMessgae'
await md.update({ data: new Uint8Array(buffer.from(message).buffer) })
const mdOutput = await md.digest()
PromptManager.getInstance().success(`${mdOutput.data.toString()}`)
console.log(`wsf: ${mdOutput.data.toString()}`)
const mdLength = md.getMdLength()console.log(`wsf: mdLength = ${mdLength}`)