收录日期:2020/10/25 07:14:42 时间:2010-09-07 01:34:57 标签:java,security,scala,encryption,md5

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.