Back to project page android-common-utility.
The source code is released under:
Apache License
If you think the Android project android-common-utility listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.xckevin.android.util; //ww w. j a v a 2 s . c o m /** * MD ?? * * @author Kevin */ public class MD5 { public static String getMD5(String instr) { String s = null; // ????????????? 16 ???????? char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; try { java.security.MessageDigest md = java.security.MessageDigest .getInstance("MD5"); md.update(instr.getBytes()); byte tmp[] = md.digest(); // MD5 ?????????? 128 ??????? // ????????16 ???? char str[] = new char[16 * 2]; // ???????16 ??????????????? // ????????16 ?????? 32 ???? int k = 0; // ????????????????? for (int i = 0; i < 16; i++) { // ?????????????? MD5 ????????? // ??????16 ???????? byte byte0 = tmp[i]; // ???? i ???? str[k++] = hexDigits[byte0 >>> 4 & 0xf]; // ????????4 ?????????, // >>> // ???????????????????????? str[k++] = hexDigits[byte0 & 0xf]; // ????????4 ????????? } s = new String(str).toUpperCase(); // ?????????????????? } catch (Exception e) { } return s; } }