Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

227
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda