You can just trim the hash string to the desired length.
Main Topics
Browse All TopicsWe need to hash ASCII text and store the hash in a database field with a length of 20. It needs to be encoded using printable characters (and XML encoded as well).
I can use the .NET built-in MD5CryptoProvider to create a 128-bit hash, which when base64 encoded, produces a 24 byte string.
I understand that a smaller hash could produce more false positive similar hashes on different text, but the criticality of uniqueness is pretty low.
I still need it in 20 bytes. Anyone familiar with a 96-bit hashing algorithm? Any other ideas on how to encode differently to accomplish this?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
While I understand that leaving off 1 byte will *effectively* mimic a 96-bit hash, there is some concern as to which bytes are more significant from the MD5 calculation.
I did find that I could implement an Ascii85 encoding that yields a 4:5 bloat instead of the 2:3 bloat that base64 produces. This can also be implemented such that the 5 characters that would need to be XML encoded would not be used.
With that, 16 bytes could be encoded into 20 bytes and be XML safe.
Yea! Problem solved. Now, where did I put that Ascii85 source code?
Business Accounts
Answer for Membership
by: gregcmcsePosted on 2008-07-03 at 11:10:07ID: 21927827
I'm not aware of any, but I'm curious as to why you don't alter the database to support a longer string? That's not usually a big deal.