Answered by:
Windows::Security::Cryptography::Core::HashAlgorithmProvider

Question
-
Is there a way to provide data to the hasher a little at a time... for example, I'm downloading a very large file in may app and so I'm seeing all the data in the file in chunks of 1-32K (depending on the scenario. At the end I want to provide a hash of the file to send back to the remote side.
So I'd like to pass buffers into the hasher as I go along and then ask for the entire hash at the end.
I found HashData(), but it appears to want the entire data-set to hash all at once.
Thanks,
Joseph
Monday, September 26, 2011 12:15 AM
Answers
-
Hi Joseph,
You can use Append function for incremental hash. Please refer following code snippet for example.
HashAlgorithmProvider TestHAP;
CryptographicHash TestCH;
IBuffer digest;String vectorString; // Fill this with your data
TestHAP = HashAlgorithmProvider::OpenAlgorithm(algName); // you can choose i.r SHA256
IBuffer vector = CryptographicBuffer::ConvertStringToBinary(vectorString, BinaryStringEncoding::Utf8);
TestCH = TestHAP->CreateHash();
TestCH->Append(vector);
TestCH->Append(vector1); // vector1 can be created same as vector
digest = TestCH->GetValue(); // THis call will return the hash in digest
Sandeep Kumar- Marked as answer by Joseph Galbraith Tuesday, September 27, 2011 4:42 AM
Tuesday, September 27, 2011 3:45 AM
All replies
-
Hi Joseph,
You can use Append function for incremental hash. Please refer following code snippet for example.
HashAlgorithmProvider TestHAP;
CryptographicHash TestCH;
IBuffer digest;String vectorString; // Fill this with your data
TestHAP = HashAlgorithmProvider::OpenAlgorithm(algName); // you can choose i.r SHA256
IBuffer vector = CryptographicBuffer::ConvertStringToBinary(vectorString, BinaryStringEncoding::Utf8);
TestCH = TestHAP->CreateHash();
TestCH->Append(vector);
TestCH->Append(vector1); // vector1 can be created same as vector
digest = TestCH->GetValue(); // THis call will return the hash in digest
Sandeep Kumar- Marked as answer by Joseph Galbraith Tuesday, September 27, 2011 4:42 AM
Tuesday, September 27, 2011 3:45 AM -
Thanks.
I had a level of indirection missing in my head... I'd found OpenAlgorithm(), but hadn't looked closely at the documentation and thought it returned a hasher... and then found the HashData() function and thought that was it... my bad.
Thanks for the code snippet and for the fish slap to wake me up to the docs :-)
Joseph
Tuesday, September 27, 2011 4:47 AM -
hi,
this is very useful. However is there anyway of seeding the HASH with a predefined key. I want to use this for accessing Azure tables which has storage key to seed the SHA256 hash. Thanks
Thursday, October 20, 2011 1:40 AM