Aleksei Pupyshev
Aleksei Pupyshev

Reputation: 63

sha256 returns strange 44 symbols hash (not 64 as usual)

I'm trying to use built-in function "sha256" in my Waves dApp. https://docs.wavesplatform.com/en/ride/built-in-functions.html

'DataEntry("sha256_kotobytesto64", toBase64String(sha256(toBytes("Message to hash"))))'

But it seems like the result of this function is not the same as major open source sha256 implementations (https://www.xorbin.com/tools/sha256-hash-calculator):

Text: Message to hash

RIDE: 8apFsPX2cDRo+bm8K5h01PprABoXDQ8TKqWibQDQx+U=

Standart: f1aa45b0f5f6703468f9b9bc2b9874d4fa6b001a170d0f132aa5a26d00d0c7e5

How to solve it?

Upvotes: 1

Views: 626

Answers (2)

Aleksei Pupyshev
Aleksei Pupyshev

Reputation: 63

base-16 will be supported in near future

I used a bit different approach with waves-crypto lib

base58encode(sha256(stringToUint8Array("string"))) from client-side

DataEntry("key_string", toBase58String(sha256(toBytes("string"))))

It'll help with any commit-reveal based smart contracts in RIDE for dApps

Upvotes: 1

user94559
user94559

Reputation: 60153

Those are the same value, encoded in different ways. The "RIDE" result is in base-64, and the "Standart [sic]" result is in hexadecimal (base-16).

Here's Python code to convert from one to the other:

>>> import base64
>>> import binascii
>>> binascii.hexlify(base64.b64decode('8apFsPX2cDRo+bm8K5h01PprABoXDQ8TKqWibQDQx+U='))
b'f1aa45b0f5f6703468f9b9bc2b9874d4fa6b001a170d0f132aa5a26d00d0c7e5'

Upvotes: 2

Related Questions