.pack(“ h*”)]。
在Ruby中,我使用函数.pack(“ H*”)]。pack(“ m0”)
将十六进制消息字符串编码为base64字符串。
前任。
msg_hex = 8308862831031591345F010101020663602A06E300000000EF934E0C5B29E50E000000000000000000000310000000004F04010000010000
msg_hex.pack("H*")].pack("m0") => gwiGKDEDFZE0XwEBAQIGY2AqBuMAAAAA75NODFsp5Q4AAAAAAAAAAAAAAxAAAAAATwQBAAABAAA=
在JavaScript中,我正在寻找一种等效方法将消息转换为64base消息。一些答案告诉使用buffer.from(msg_hex).tostring('Base64')
,但结果是不同的。
const msg_hex = 8308862831031591345F010101020663602A06E300000000EF934E0C5B29E50E000000000000000000000310000000004F04010000010000
Buffer.from(msg_hex).toString('base64') // => ODMwODg2MjgzMTAzMTU5MTM0NUYwMTAxMDEwMjA2NjM2MDJBMDZFMzAwMDAwMDAwRUY5MzRFMEM1QjI5RTUwRTAwMDAwMDAwMDAwMDAwMDAwMzEwMDAwMDAwMDA0RjA0MDAwMDAwMDEwMDAw
.pack(“ h*”)]。javascript中Ruby的
的等效方法是什么?
In Ruby, I use function .pack("H*")].pack("m0")
to encode a hex message string to base64 string.
ex.
msg_hex = 8308862831031591345F010101020663602A06E300000000EF934E0C5B29E50E000000000000000000000310000000004F04010000010000
msg_hex.pack("H*")].pack("m0") => gwiGKDEDFZE0XwEBAQIGY2AqBuMAAAAA75NODFsp5Q4AAAAAAAAAAAAAAxAAAAAATwQBAAABAAA=
In Javascript, I am looking for an equivalent method to convert message to 64base message. Some answers tell useing Buffer.from(msg_hex).toString('base64')
, but the result is different.
const msg_hex = 8308862831031591345F010101020663602A06E300000000EF934E0C5B29E50E000000000000000000000310000000004F04010000010000
Buffer.from(msg_hex).toString('base64') // => ODMwODg2MjgzMTAzMTU5MTM0NUYwMTAxMDEwMjA2NjM2MDJBMDZFMzAwMDAwMDAwRUY5MzRFMEM1QjI5RTUwRTAwMDAwMDAwMDAwMDAwMDAwMzEwMDAwMDAwMDA0RjA0MDAwMDAwMDEwMDAw
what is the equivalent method for .pack("H*")].pack("m0")
of Ruby in Javascript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您几乎可以在那里提供的东西。
您只需忘记告诉
buffer.from
您提供的内容,如发送字符串,默认情况下它只是将其存储为字符串。但是您想要的是将源代源解码为十六进制,然后将其存储为二进制。所以做 - >
IOW:您只是错过了第二个参数
hex
。You was nearly there with what you supplied.
You just forgot to tell
Buffer.from
what you was supplying, as default if you send a string it's just going to store it as a string. But what you wanted was to decode the source as hex and then store as binary.So doing ->
IOW: you just missed the second parameter
hex
..