I'm converting an old node.js lib into python and can't reproduce the behaviour of Buffer.toString() in python.
maybe i sould use something different than latin-1 and utf-8 ?
CodePudding user response:
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
.
CodePudding user response:
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