Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

228
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda