In the application development often need to download the successful file for MD5 check, is to get a message digest of a file, each file generated digest is unique, generated message digest is 128 bits (16 bytes) of data, generally need to convert them into 16 binary strings. Converting a decimal number to 16 can use integer.tohexstring (int num), as long as the low eight bits can use 0xFF & num to intercept only the low eight bits of the 32-bit integer value.
Test procedure:
MessageDigest degest = messagedigest.getinstance ("MD5"); FileInputStream InputStream=new fileinputstream ("test.txt");D igestinputstream dis=New new StringBuffer (); for (int i = 0; i < sumary.length; i++) { strbuffer.append (integer.tohexstring (0xFF & Sumary[i]);//As long as the integer data of the low eight-bit}system.out.println (strbuffer.tostring ());
Android verifies the integrity of downloaded files