Skip to content

Instantly share code, notes, and snippets.

@openrijal
Created May 1, 2013 12:17
Show Gist options
  • Save openrijal/5494992 to your computer and use it in GitHub Desktop.
Save openrijal/5494992 to your computer and use it in GitHub Desktop.
This method converts any String to MD5 encrypted Strings.
/*
Input: STRING -- something like "myplainpassword"
Output: MD5 STRING -- something like "79054025255fb1a26e4bc422aef54eb4"
*/
public static String convertToMd5(final String inputString) throws UnsupportedEncodingException {
StringBuffer sb = new StringBuffer();
try {
final java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
final byte[] array = md.digest(md5.getBytes("UTF-8"));
for (int i = 0; i < array.length; ++i) {
sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3));
}
return sb.toString();
} catch (final java.security.NoSuchAlgorithmException e) {
}
return sb.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment