Created
May 1, 2013 12:17
-
-
Save openrijal/5494992 to your computer and use it in GitHub Desktop.
This method converts any String to MD5 encrypted Strings.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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