Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problems with decryption using MD5

843810Dec 23 2002 — edited Dec 30 2002
I am using MD5 to encrypt a password and store it in a Database table as a String. The password encryption works fine but when I retrieve the password and compare it against the password the user has entered (after encrypting it), it doesn't match. Everytime I ask for the password String, MD5 appears to encrypt it into a different value, even if it is the same input String value.

I am using JDK 1.3 and the method is called in a servlet. My code follows below as well as the output from the routine.

public String encrypt(String password)
{
String encryptPassWord = new String("");
try
{
MessageDigest md5 = MessageDigest.getInstance("MD5");
byte[] pWord = password.getBytes();
md5.update(pWord);
byte[] pWord1Digest = md5.digest();
encryptPassWord = pWord1Digest.toString();
}
catch ( NoSuchAlgorithmException e )
{
System.err.println("ALSUserBean method encrypt()");
System.err.println(e.getMessage());
}
return encryptPassWord;
}

*****ALSUserBean encrypt() password String before encryption "111111"
*****ALSUserBean encrypt() password after encryption "[B@4832d2"
*****ALSUserBean Password in DB table "[B@5f5a8f" [] UID [709] [703]

*****ALSUserBean encrypt() password String before encryption "111111"
*****ALSUserBean encrypt() password after encryption "[B@587c94"
*****ALSUserBean setLogonInput() Password in DB Table "[B@5f5a8f"

*****ALSUserBean encrypt() password String before encryption "111111"
*****ALSUserBean encrypt() password after encryption "[B@5b0afd"
*****ALSUserBean setLogonInput() Password in DB Table "[B@5f5a8f"

Please help.

Thanx

Simon Fisher

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 27 2003
Added on Dec 23 2002
3 comments
313 views