javascript - 如何在 Node 中将 Hex 转换为 Uint8Array?

标签 javascript node.js

我可以使用以下代码将 Uint8Array 转换为十六进制

 var bkh = {
    publicKey: new Uint8Array([91, 221, 234, 40, 144, 246, 91, 187, 154, 76,
        60, 178, 204, 81, 35, 195, 254, 114, 246, 88, 90, 170, 68, 97, 199,
        170, 72, 36, 107, 66, 206, 9]
    ),

    secretKey: new Uint8Array([64, 68, 196, 103, 210, 179, 166, 40, 187,
        150, 167, 233, 144, 206, 64, 26, 77, 133, 70, 238, 232, 227, 133,
        83, 149, 202, 213, 41, 152, 243, 237, 41]
    )
}

let hex = Buffer.from(bkh.publicKey).toString('hex');

console.log('master key',hex)

如何在 Node 中将此 hex 值转换回 Uint8Array

最佳答案

var hex = '5bddea2890f65bbb9a4c3cb2cc5123c3fe72f6585aaa4461c7aa48246b42ce09'
new Uint8Array(Buffer.from(hex, 'hex'))
// or 
Uint8Array.from(Buffer.from(hex, 'hex'))

关于javascript - 如何在 Node 中将 Hex 转换为 Uint8Array?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55260675/

相关文章:

javascript - 输入键重新加载页面

javascript - 如何使用discord.js 创建具有权限的discord 类别?

node.js - 运行 forEach 后返回变量

node.js - Node js 导出模块在导入它的另一个文件中返回未定义的值

javascript - 客户端可以接收事件但不能发出

javascript - 如何为 jQuery DataTable 设置名称

javascript - 如果 div 不为空,则从 dom 中删除 X

javascript - Ionic App 的 Karma 单元测试。错误 : [ng:areq] Argument 'StockCtrl' is not a function, 未定义

java - ext js 与 .jsp、java 后端兼容吗?

javascript - 在所有文件中全局导入ReactJS组件