Created
March 7, 2013 13:56
-
-
Save stden/5108213 to your computer and use it in GitHub Desktop.
Вычисление MD5-хеша
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
/** | |
* Вычисление MD5-хеша | |
* | |
* @param str Строка, для которой считаем MD5-хеш сумму | |
* @return MD5-хеш строки | |
*/ | |
public static String MD5(String str) { | |
try { | |
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); | |
byte[] array = md.digest(str.getBytes()); | |
StringBuilder sb = new StringBuilder(); | |
for (byte anArray : array) { | |
sb.append(Integer.toHexString((anArray & 0xFF) | 0x100).substring(1, 3)); | |
} | |
return sb.toString(); | |
} catch (java.security.NoSuchAlgorithmException e) { | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment