Advertisement
NgThanhPhuc

Android_MD5

May 9th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. public static final String md5(final String s) {
  2. try {
  3. // Create MD5 Hash
  4. MessageDigest digest = java.security.MessageDigest
  5. .getInstance("MD5");
  6. digest.update(s.getBytes());
  7. byte messageDigest[] = digest.digest();
  8. // Create Hex String
  9. StringBuffer hexString = new StringBuffer();
  10. for (int i = 0; i < messageDigest.length; i++) {
  11. String h = Integer.toHexString(0xFF & messageDigest[i]);
  12. while (h.length() < 2)
  13. h = "0" + h;
  14. hexString.append(h);
  15. }
  16. return hexString.toString();
  17. } catch (NoSuchAlgorithmException e) {
  18. e.printStackTrace();
  19. }
  20. return "";
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement