MD5, md5 decryption
1 public class MD5 {2 3 // Global Array 4 private final static String [] strDigits = {"0", "1", "2", "3 ", "4", "5", "6", "7", "8", "9", "a", "B", "c", "d ", "e", "f"}; 6 7 // return format: Numbers and strings 8 private static String byteToArrayString (byte bByte) {9 int iRet = bByte; 11 if (iRet <0) {12 iRet + = 256; 13} 14 int iD1 = iRet/16; 15 int iD2 = iRet % 16; 16 return strDigits [iD1] + strDigits [iD2]; 17} 18 19 // convert the byte array to a hexadecimal String of 20 private static String byteToString (byte [] bByte) {21 StringBuffer sBuffer = new StringBuffer (); 22 for (int I = 0; I <bByte. length; I ++) {23 sBuffer. append (byteToArrayString (bByte [I]); 24} 25 return sBuffer. toString (); 26} 27 28 public static String GetMD5Code (String strObj) {29 String resultString = null; 30 try {31 resultString = new String (strObj ); 32 MessageDigest md = MessageDigest. getInstance ("MD5"); 33 resultString = byteToString (md. digest (strObj. getBytes (); 34} catch (NoSuchAlgorithmException ex) {35 ex. printStackTrace (); 36} 37 return resultString; 38} 39}