Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
what is the equivalent method for .pack("H*")].pack("m0") of Ruby in Javascript?

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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 ->

Buffer.from(msg_hex, 'hex').toString('base64') 

IOW: you just missed the second parameter hex..

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!