How to calculate hash of a string vector?

17 views
Skip to first unread message

Devharsh Trivedi

unread,
Feb 2, 2022, 12:19:25 PMFeb 2
to Crypto++ Users
I am trying to calculate SHA256 digest for entire string vector like this:

byte digest[SHA256::DIGESTSIZE];
SHA256().CalculateDigest(digest, (const byte*)stringVector.data(), stringVector.size());

What is the correct way to calculate hash of entire vector?

Devharsh Trivedi

unread,
Feb 2, 2022, 4:39:45 PMFeb 2
to Crypto++ Users
I am using hash.Update to iterate over a vector to calculate the hash of the container. Is there a better way to do this?

std::string digest;
SHA256 hash;

for(auto str: stringVector) { 
hash.Update((const byte*)str.data(), str.size()); 

digest.resize(hash.DigestSize()); 
hash.Final((byte*)&digest[0]);

Jeffrey Walton

unread,
Feb 2, 2022, 9:25:09 PMFeb 2
to Crypto++ Users List
Reply all
Reply to author
Forward
Message has been deleted
0 new messages