My code to generate md5 looks like
@Nonnull
static String getAuthCode(@Nonnull final String email, @Nonnull final String memberExternalId,
@Nonnull final String clientId, @Nonnull final String clientSecret) {
final MessageDigest messageDigest = getMessageDigest("MD5");
final String stringForHashCode = email + ":" + memberExternalId + ":" + clientId + ":" + clientSecret;
messageDigest.update(stringForHashCode.getBytes());
return new BigInteger(1, messageDigest.digest()).toString();
}
I run the test as
@Test
public void test() {
System.out.println(getAuthCode("a", "b", "c", "d"));
}
and I get the output as
306937959255909402080036399104389354327
When I run the same test on online website, I get the output as
e6ea19c62a3763c7b78c475652c51357
for same input a:b:c:d
Question
- Why are they different?
- How can I get the output similar to what I get online? which is
e6ea19c62a3763c7b78c475652c51357?
messageDigest.update(stringForHashCode.getBytes());<-- this will use the default JVM encoding. Is that what you want? Rule of thumb: always specify the encoding!messageDigest.update(stringForHashCode.getBytes(Charset.forName("UTF-8")));but the result is still the same