Created
July 13, 2015 15:17
-
-
Save tehcpu/07ec892d2dd96ee64b8f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public static String md5Custom(String st) { | |
MessageDigest messageDigest = null; | |
byte[] digest = new byte[0]; | |
try { | |
messageDigest = MessageDigest.getInstance("MD5"); | |
messageDigest.reset(); | |
messageDigest.update(st.getBytes()); | |
digest = messageDigest.digest(); | |
} catch (NoSuchAlgorithmException e) { | |
// тут можно обработать ошибку | |
// возникает она если в передаваемый алгоритм в getInstance(,,,) не существует | |
e.printStackTrace(); | |
} | |
BigInteger bigInt = new BigInteger(1, digest); | |
String md5Hex = bigInt.toString(16); | |
while( md5Hex.length() < 32 ){ | |
md5Hex = "0" + md5Hex; | |
} | |
return md5Hex; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment