1

A java implementation creates two different digest for a same input string, if i run as stand alone application or running inside a web application.

The standalone application matches with oracle dbms The implementation is

    MessageDigest md5 = MessageDigest.getInstance("MD5");

    if (md5 != null) {
        md5.reset();
        newHashByte = md5.digest(msg.getBytes());
    }

    newHash = convertToString(newHashByte);

Hex to String conversion implementation is

StringBuffer result = new StringBuffer(64);

for (int i = 0; i < digestBits.length; i++)
    hexDigit(result, digestBits[i]);

return result.toString();

Highly appreciate if you could help us resolving this.

2 Answers 2

7

I suspect you have different default encodings. Use the correct encoding like this,

newHashByte = md5.digest(msg.getBytes("utf-8"));
Sign up to request clarification or add additional context in comments.

Comments

2

Where does msg come from in each case? I think it's likely you have a newline character on the end in one case but not the other. It's also possible that your character encodings are set differently somehow in the two scenarios. I highly doubt that anything else in your example is changing except msg.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.