Created
September 17, 2017 04:47
-
-
Save deepankarb/b474b89a1081bd3be9533ace61c9c9a5 to your computer and use it in GitHub Desktop.
java 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
public static String md5(String in) { | |
byte[] bytes; | |
StringBuilder hashtext; | |
try { | |
bytes = in.getBytes("UTF-8"); | |
MessageDigest md = MessageDigest.getInstance("MD5"); | |
byte[] digest = md.digest(bytes); | |
BigInteger bigInt = new BigInteger(1, digest); | |
hashtext = new StringBuilder(bigInt.toString(16)); | |
while (hashtext.length() < 32) { | |
hashtext.insert(0, "0", 0, 1); | |
} | |
} catch (UnsupportedEncodingException e) { | |
throw new RuntimeException(e.getMessage()); | |
} catch (NoSuchAlgorithmException e) { | |
throw new RuntimeException(e.getMessage()); | |
} | |
return hashtext.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment