Public classTtgameMd5 { Public Final Staticstring MD5 (String str) {CharHexdigits[] = {//the character used to convert a byte into a 16 binary representation' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ', ' A ', ' B ', ' C ', ' d ', ' E ', ' F ' }; Try { byte[] strtemp =str.getbytes (); MessageDigest mdtemp= Messagedigest.getinstance ("MD5"); Mdtemp.update (strtemp); byteTmp[] = Mdtemp.digest ();//the MD5 evaluates to a 128-bit long integer,//in bytes, that's 16 bytes . CharStrs[] =New Char[16 * 2];//each byte is represented by a 16 binary, using two characters,//so 32 characters are required to represent 16 binary intk = 0;//represents the corresponding character position in the transformation result for(inti = 0; I < 16; i++) {//starting with the first byte, each byte of the MD5//Convert to 16-character conversion byteBYTE0 = Tmp[i];//take the first I bytestrs[k++] = hexdigits[byte0 >>> 4 & 0xf];//takes a 4-bit numeric conversion in bytes,//>>> moves the symbol bit right with the right shift for logicstrs[k++] = hexdigits[byte0 & 0xf];//the number conversion of the lower 4 bits in the fetch byte }//return new String (STRs). toUpperCase ();//converted result to string return NewString (STRs);//converted result to string}Catch(Exception e) {return NULL; } }
MD5 Encryption--32-bit 16 binary lowercase