I was tasked with writing a Java app with client-side authentication, with the ability to save the login information. So I needed to encode the password when saving the configuration to disk and also before sending login credentials through HTTPS. You think getting that information is a simple one line method call to a Java API? Hells no.

I obviously started via Google search, trying one of the first MD5 implementation results using Java’s MessageDigest class. This code is just wrong. I came across a couple strings that weren’t encoded to the same hexadecimal as MySQL’s md5() function. A couple entries down in Google’s search return was a more concise chunk of MD5 code. However, there was still an issue since its returned string wasn’t a 32 character length string that could be used to compare against a MySQL md5() password column. Here’s a proper method, with left zero padding: