I am trying to calculate the private data object's hash using sha256 hashing algorithm. The requirement is to calculate the hash of private data object and match it with the hash stored on the ledger but both hashes do not match. I am using Hyperledger fabric v2.3.3
For example, the private data object is:
const data = {
"assetType": "PART",
"partNumber": "3415",
"serialNumber": "312351234123"
};
Below is the code executed to save private data:
await stub.putPrivateData('collection_org1', `PVT-${id}`, Buffer.from(JSON.stringify(data)))
The hash calculated using crypto.createHash('sha256').update(JSON.stringify(dataString)).digest('hex')
prints the following hash:
ae2fda8277f53ccd0b9de91ccc2c289142e0030f423966f706686bc1b5fe2e6e
using shasum,
❯ echo -n "{\"assetType\":\"PART\",\"partNumber\":\"3415\",\"serialNumber\":\"312351234123\"}" | shasum -a 256
ae2fda8277f53ccd0b9de91ccc2c289142e0030f423966f706686bc1b5fe2e6e -
but the hash on the ledger fetched using stub.getPrivateDataHash()
returns:
559f3ed03c81003bdb67efb83c3a90b6aac4d0169c40aa74a68fbf43f7eeb699
If I query the private data of the key, it returns the exact above object. Am I doing something wrong here?