Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21370

[RESOLVED] SHA256 output is different from the correct value

$
0
0
I am trying to get the SHA256 hash value for the following string:

800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D

The value generated by the VB code I am using is

e2e4146a36e9c455cf95a4f259f162c353cd419cc3fd0e69ae36d7d1b6cd2c09

And this is correct, as verified by online SHA256 generators such as http://www.xorbin.com/tools/sha256-hash-calculator

The problem is, according to this guide, the output should be

8147786C4D15106333BF278D71DADAF1079EF2D2440A4DDE37D747DED5403592

This discrepancy has been explained in PHP code by a stackoverflow user

Quote:

This is because you are hashing the literal string

"800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D"
This is not what what needs to happen. This is a string of bytes. It's in HEX format just to make viewing it easier. In reality, this represents a binary string. That's what you need to be hashing.

hex2bin is your friend here.

<?php
$hex = '800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D';
echo hash('sha256', hex2bin($hex));

DEMO: https://eval.in/69440
How can I do this in VB6? Please help.

Viewing all articles
Browse latest Browse all 21370

Trending Articles