-6

Possible Duplicate:
Generate MD5 hash in Java

MD5 hash was generated using javascript function. Requriement is to generate the MD5 hash generation in java.

On javaScript side, the password was being passed to str_md5() method of Paul Johnston implementation of MD5. How can this be performed in java?

     MessageDigest md = MessageDigest.getInstance("MD5");
    md.update(password.toUpperCase().getBytes());

    byte byteData[] = md.digest();

    //convert the byte to hex format
    StringBuffer hexString = new StringBuffer();
    for (int i=0;i<byteData.length;i++) {
        String hex=Integer.toHexString(0xff & byteData[i]);
        if(hex.length()==1) hexString.append('0');
        hexString.append(hex);
    }

   Javascript
    v_password = jQuery.trim(v_password);
v_userid = jQuery.trim(v_userid);
var v_digest = str_md5(v_password.toUpperCase()); // Implementation in java?
var v_pswdDigest = hex_md5(v_digest + v_userid.toUpperCase());
return v_pswdDigest;
2
  • 3
    You can use a search engine, such as google, to search for how to apply the md5 hash in Java. Otherwise, please include in your question what you've tried. Commented Jan 24, 2013 at 18:52
  • Yes please include what you have tried ? Commented Jan 14, 2014 at 8:34

1 Answer 1

0

The MessageDigest class can be used to generate hashes, including MD5 hashes

Sign up to request clarification or add additional context in comments.

3 Comments

How can we obtain the same hash that is being generated using javascript code? If the hash does not match, the user login fails.
@user1978406, if you're hashing passwords client side, and using md5 as your hashing algorithm, you're doing authentication very very wrong.
Make sure you're using the same encoding on both sides. UTF-8 is a good rule of thumb.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.