File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Security and the fly likes problem in MD5 encryption and Decryption Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Security
Bookmark "problem in MD5 encryption and Decryption" Watch "problem in MD5 encryption and Decryption" New topic
Author

problem in MD5 encryption and Decryption

Prash Singh
Ranch Hand

Joined: Aug 23, 2009
Posts: 103

Dear all,


I just created a code for encrypting a String using MD5 algorithm.
The code snippet is like this:


public static final String md5(String str) {

MessageDigest md = null;
try {
md = MessageDigest.getInstance("MD5");
}
catch (NoSuchAlgorithmException e) {
return null;
}


md.reset();
md.update(str.getBytes());
byte[] hash = md.digest();



StringBuffer encryptedStr = new StringBuffer();
int v = 0;
for (int i = 0; i < hash.length; i++) {
v = hash[i] & 0xFF;
if (v < 16) {
encryptedStr.append("0");
}
encryptedStr.append(Integer.toString(v, 16).toUpperCase());
}

return encryptedStr.toString();
}


----> As far as I am concerned , this code generates the encrypted string efficiently and correctly.
Now I want to decrypt the encrypted string.


Please Suggest me what to do.




Thanks in Advance.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41839
    
  63
MD5 is not a *cipher*, it is a *hash* (or *digest*). As such, it can't be reversed (or unencrypted, as you call it). I suggest you look into the AES or Triple-DES algorithms.


Ping & DNS - my free Android networking tools app
Prash Singh
Ranch Hand

Joined: Aug 23, 2009
Posts: 103

Dear Ulf,

Thanks for your reply.
It seems like I would have to change my encryption scheme.

But thanks for clearing Doubts.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in MD5 encryption and Decryption