Skip to content

Instantly share code, notes, and snippets.

@stden
Created March 7, 2013 13:56
Show Gist options
  • Save stden/5108213 to your computer and use it in GitHub Desktop.
Save stden/5108213 to your computer and use it in GitHub Desktop.
Вычисление MD5-хеша
/**
* Вычисление 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