Skip to content
This repository has been archived by the owner on Dec 23, 2020. It is now read-only.

SHA256Digest.process return data not equal to hashlib(python) and other lib in many other languages #198

Open
ipconfiger opened this issue Jul 3, 2019 · 3 comments

Comments

@ipconfiger
Copy link

source text is '1d31dc56a882c686e5355f367d2ea8393ef8535f19896e38c83f025062837e901d0400551802c5533661aabc96135de5eb91a982fdb9ba3a876043b8e883ae50'

SHA256Digest.process returns:
[209, 176, 92, 12, 94, 11, 223, 105, 236, 152, 90, 14, 40, 177, 184, 200, 217, 84, 250, 223, 10, 57, 94, 148, 101, 239, 149, 235, 193, 91, 136, 188]

Python hashlib sha256 returns:

[107, 25, 91, 95, 40, 19, 177, 140, 73, 50, 217, 152, 219, 191, 24, 89, 72, 242, 227, 38, 197, 232, 11, 4, 206, 241, 52, 249, 79, 92, 62, 171]

@simbados
Copy link

simbados commented Sep 5, 2019

How did you transform the source text? Might be an encoding issue as you need a Uint8List to hash a String.

@stevenroose
Copy link
Member

source text is '1d31dc56a882c686e5355f367d2ea8393ef8535f19896e38c83f025062837e901d0400551802c5533661aabc96135de5eb91a982fdb9ba3a876043b8e883ae50'

Is that the actual text in UTF8? Or is that a hexadecimal representation of the source bytes? Could you briefly mention the code you used to get those hash values for both Dart and Python?

Sorry for the late response, not really keeping track on this project anymore.

@richardheap
Copy link
Collaborator

Apparently the source text is an ASCII string to be converted to bytes as ASCII values, i.e. 0x31, 0x64, 0x33, 0x31, etc.

The following BC code produces the expected output:

  var sourceText =
      '1d31dc56a882c686e5355f367d2ea8393ef8535f19896e38c83f025062837e901d0400551802c5533661aabc96135de5eb91a982fdb9ba3a876043b8e883ae50';

  var bytes = Uint8List.fromList(sourceText.codeUnits);
  print(bytes.length);

  print(SHA256Digest().process(bytes));

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants