> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Georgie Porgie
> Sent: Tuesday, May 11, 2004 6:29 PM
> To: [EMAIL PROTECTED]
> Subject: A shorter hash code?
> 
> 
> So I'm trying to hash a string, and I want to get back 
> something shorter than 32 characters.� The following code 
> always returns 32 characters, even if I pass in a string 
> that's one character long:
> �
> 
> CryptoPP::MD5 md5;
> CryptoPP::HashFilter md5Filter(md5, new
> CryptoPP::HexEncoder);
> 
> // toHash is just a std::string
> std::string toHash(toHash); 
> md5Filter.Put((byte*)toHash.c_str(),toHash.length());
> md5Filter.MessageEnd();
> 
> Thanks for any help!

Hello,

Each hash class has a constant defined <class>::DIGESTSIZE. In the case of
MD5, CryptoPP::MD5::DIGESTSIZE will return 16 [bytes]. See
http://www.rsasecurity.com/rsalabs/faq/3-6-6.html. The hex encoder will
double the size of the binary message\hash.

If you want a shorter hash, consider CRC. I do not claim it is collision
resistant, nor that it is secure. However, it is only 4 bytes...

Jeff

Jeffrey Walton

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to