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

225
Views
node.js 6.0.0 buffer to string equivalent in python3

I'm converting an old node.js lib into python and can't reproduce the behaviour of Buffer.toString() in python.

this lib is use in a node 6.0.0 environment

I did take a look at this node issue, but i don't understand if it's linked to my problem.

js function:

const KDF_PARTY_V = Buffer.from('E6F8C08930597B47472620568D207A23E4FCEF4B3F0AA3DC26FF369C622C6E1D', 'hex').toString('binary') 
// The SHA-256 hash of your ID string literal; 32 bytes in size.
console.log(KDF_PARTY_V)

output:

æøÀ0Y{GG& V z#äüïK?
£Ü&ÿ6b,n

python equivalent:

kdf_v = memoryview(bytes.fromhex('E6F8C08930597B47472620568D207A23E4FCEF4B3F0AA3DC26FF369C622C6E1D')).tobytes().decode('latin-1')
print(kdf_v)

the output (badly shown by stack)

æøÀ‰0Y{GG& V z#äüïK?
£Ü&ÿ6œb,n

My actual console message: enter image description here maybe i sould use something different than latin-1 and utf-8 ?

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

0

it was just a console caracter encoding mistake

when looking at the binary data itself the python version is the same as the js one so:

kdf_v = bytes.fromhex(merchant_id).decode('latin1')

work perfectly

@AKX i do need to have the variable in str format, because i use it in a concatenation and the result of it in a sha256 digest

about 4 years ago · Juan Pablo Isaza Report

0

Just don't try to decode at all. Decoding turns bytestrings into text strings, and a hash isn't a text string.

kdf_v = bytes.fromhex('E6F8C08930597B47472620568D207A23E4FCEF4B3F0AA3DC26FF369C622C6E1D')

gives you a 32-byte bytes object, which is functionally equivalent to a Node.js Buffer.

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!