According to the answer pointed to by @ypercube, MySQL PASSWORD() is just sha1, applied twice.
Using Apache Commons Codec:
public static String MySQLPassword(String plainText) throws UnsupportedEncodingException {
byte[] utf8 = plainText.getBytes("UTF-8");
return "*" + DigestUtils.shaHex(DigestUtils.sha(utf8)).toUpperCase();
}
EDIT: tested, added throws clause, uppercased and a prefix "*".
Working code (to replace shaHex() that was not working):
public static String MySQLPassword(String plainText)
throws UnsupportedEncodingException
{
byte[] utf8 = plainText.getBytes("UTF-8");
byte[] test = DigestUtils.sha(DigestUtils.sha(utf8));
return "*" + convertToHex(test).toUpperCase();
}