Hash functions such as SHA-256 takes a binary string as input. Now given a hex string when we convert it to a normal text string the computed SHA-256 value would be the same. Herein lies my problem
Let us consider a simple string in hexadecimals 2E
;
its SHA-256 value is cdb4ee2aea69cc6a83331bbe96dc2caa9a299d21329efb0336fc02a82e1839a8
.
When converted into byte form should we write 46
or 046
. In either case the SHA-256 output is not matching:
For 46
you'd get
25fc0e7096fc653718202dc30b0c580b8ab87eac11a700cba03a7c021bc35b0c
.
For 046
you'd get b2d084ae2bd0f4b38953ea3adb009b4f059816f93392addbcfb373399f183e88
.
How do we convert from hexadecimals to a byte so the result is the same? What are the rules? As far as I know SHA-256 requires byte format.
I've used this (GitHub) software for calculating the SHA-256 values.
46
(resp.046
) when encoded to as many bytes per ASCII or UTF-8, that is the bytes 0x34 0x36 (resp. 0x30 0x34 0x36) where the 0x prefix is for hexadecimal. $\endgroup$