I've been stuck in this for a while, for the life of me.
I have this thing in python3
msg = "6NmByERB9ZDJX9OKDtIzpGl8ei7KBiYI"+"\n"+"1623776851607"+"\n"+"/api2/v2/users/me"+"\n"+"0"
message = msg.encode('utf-8')
hash_object = hashlib.sha1(message)
sha_1_sign = hash_object.hexdigest()
print(sha_1_sign)
# 4ff521a9b87ddd0dea00a842f8f5d72819f9df0a
but I cannot GET THIS SAME HASH in NodeJS, I've tried a lot of solutions; at first I though it was the first part, the encode to utf-8, because printing that was returning different results, but it seems like that's not it, it was just different representation of the same string.
My approach in JS:
const crypto = require('crypto') // maybe another library that works in browser?
const msg = "6NmByERB9ZDJX9OKDtIzpGl8ei7KBiYI"+"\n"+"1623776851607"+"\n"+"/api2/v2/users/me"+"\n"+"0"
let shasum = crypto.createHash('sha1')
shasum.update(JSON.stringify(msg))
let hashed_string = shasum.digest('hex')
console.log(hashed_string)
// c838ca6f79551d828d6e4a810bd49c1df07b54a3
thanks for any help :)
JSON.stringify(msg)?msg !== JSON.stringify(msg). It adds"at the start and end\n.msghas length 66 andJSON.stringify(msg)has length 71.encode("utf-8"), that's why I added thestringifyandencodeURIand other methods before, but no, without that, just works, what a journey, thanks for commenting, another dumb error that took me days to resolve.