Getting different hash(sha 256) using solidity and python for same bytes

46 Views Asked by At

Solidity code

string memory str= string(abi.encodePacked(orderId, msg.sender, totalAmount));
        bytes memory encodedString = abi.encodePacked(str);
        bytes32 calculatedHash = sha256(encodedString);
        emit LogData(calculatedHash,encodedString);

I took encodedString and used it in Python code:

Python Code:

import hashlib

my_string = encodedString

my_bytes = bytes(my_string, 'utf-8')

print(hashlib.sha256(my_bytes).hexdigest())

but I am getting two different hashes from these two codes. Can someone tell me the error and correction.

I want these two hashes to be alike

0

There are 0 best solutions below