• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in MD5 encryption and Decryption

 
Prash Singh
Ranch Hand
Posts: 103
jQuery Netbeans IDE Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Prash Singh
Ranch Hand
Posts: 103
jQuery Netbeans IDE Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ulf,

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

But thanks for clearing Doubts.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic