I am trying to find some samples of how to take a string and hash it using MD5, and then be able to reverse hash (correct term?) back to the original string.
Does anyone know of any documentation that shows how this can be done, or ideally has any sample code they could share?
I've 开发者_开发技巧read about the java.security.MessageDisgest class, but that appears to be only one-way. I need to be able to convert the hash back into its original data. Is MD5 the best algorithm to use, or should i be looking at something else entirely?
MD5 is destructive. You lose data when you hash.
Perhaps you are looking for a symmetric cipher like DES or (better) AES?
The bouncycastle security provider has a DES implementation example at http://www.bouncycastle.org/specifications.html
EDIT: Sorry, I've jumped the gun. What is your objective: Compression, Indexing, Checksumming, Encryption, or something else?
Hash functions are designed to be irreversible.
What you need is to use a secure transport layer, like SSL or TLS (eg: HTTPS is HTTP with SSL or TLS). Please refrain from rolling your own on this one.
Note that simply using a symmetric cypher like AES on the client (eg: Javascript) is useless, because you'd need to supply the key to said client and thus an attacker would be able to trivially decrypt any intercepted messages.
精彩评论