I'm new to cryptography and to crypto++ in general, but I need to try a
hash chain with the library, I got this code but I have an issue
CryptoPP::Integer iRandomValue;
CryptoPP::AutoSeededRandomPool prng;
CryptoPP::SHA1 hash;
std::string digest,tmp;
std::ostringstream ossRandomValue;
//RANDOM VALUE
iRandomValue.Randomize(prng, bitsize);
ossRandomValue << iRandomValue;
tmp=ossRandomValue.str();
std::cout<<"DEC VALUE :"<<std::dec<<iRandomValue<<std::endl;
*int* i=0;
*while*(i<2)
{
std::string sHash1;
CryptoPP::HexEncoder hEncoder1(*new* CryptoPP::StringSink(sHash1));
CryptoPP::StringSource(tmp, *true*, /*PumpAll*/
*new* CryptoPP::Redirector(hEncoder1)
);
std::cout<<"ORIGINAL VALUE:"<<tmp<<":"<<std::endl;
std::cout<<"HEX ORIGINAL VALUE:"<<sHash1<<std::endl;
*int* x=0;
*if*(i<=0)
x=1;
*else*
x=0;
hash.Update((*const* CryptoPP::byte*)sHash1.data(), sHash1.size());
digest.resize(hash.DigestSize());
hash.Final((CryptoPP::byte*)&digest[0]);
CryptoPP::Integer result;
result.Decode((CryptoPP::byte*)&digest[0],hash.DigestSize());
std::ostringstream ossHashDecimal;
ossHashDecimal << result;
tmp=digest;
std::cout<<"HASH VALUE DEC:"<<tmp<<std::endl;
std::string sHash;
CryptoPP::HexEncoder hEncoder(*new* CryptoPP::StringSink(sHash));
CryptoPP::StringSource(digest, *true*, /*PumpAll*/
*new* CryptoPP::Redirector(hEncoder)
);
std::cout<<"HASH VALUE:"<<sHash<<std::endl;
i++;
}
The first hash work pretty well, but when the result of the first hash is
sent to create a new diggest the printed result doesn't match with another
calculated hash, I tried online apliying two hashes to the same values, but
don't get the same value as with these code.
Also, if anyone know if I need something to make faster the continuous
hashing I'll be most thankful
I hope someone an solve my issue.
--
You received this message because you are subscribed to "Crypto++ Users". More
information about Crypto++ and this group is available at
http://www.cryptopp.com and
http://groups.google.com/forum/#!forum/cryptopp-users.
---
You received this message because you are subscribed to the Google Groups
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/cryptopp-users/4422f662-eaac-4894-9fa3-8d7160be3a94%40googlegroups.com.