What is MD5?
Message-digest algorithm 5 (Information-Digest algorithm). Often said "MD5 encryption", is it → information-digest algorithm.
When downloading something, you often see the MD5 value in some of the compression package properties. And this download page, most likely in a certain place, wrote a sentence, the file's MD5 value is xxxxxxxxx. How does that work?
Vernacular vernacular: MD5, in fact, is an algorithm. You can put a string, or a file, or a compressed package, after executing MD5, you can generate a fixed length of 128bit string. This string is basically the only one.
Therefore, after someone has repaired the package, it will generate a new string, then you can take the Web site provided by the string and the new generated string contrast, if different, it is the person has been repaired.
Encryption and digest, is not the same
After the encrypted message is complete, has the decryption algorithm, obtains the raw data;
The information obtained is incomplete; The raw data cannot be obtained through the summary data;
MD5 length
Some people say md5,128 bit, 32 bit, 16 bit, how long is MD5?
The length of the MD5, which defaults to 128bit, is a binary string of 128 0 and 1.
It is very unfriendly to say so.
So the binary is turned into 16, each 4 bit represents a 16 binary,
So 128/4 = 32 is replaced with a 16 binary representation, which is 32 bits.
Why is there a 16-bit MD5 on the Internet?
There are many posts online, MD5 32-bit 16-bit encryption difference.
Carefully observe the 32-bit and 16-bit MD5 values generated by admin ...
Query Result:
MD5 (admin,32) = 21232F297A57A5A743894A0E4A801FC3
MD5 (admin,16) = 7a57a5a743894a0e
Look out!
In fact, the 16-bit length is from the 32-bit MD5 value. The 32-bit MD5 is removed from the first eight bits, and the last eight bits are removed.
The role of MD5
① conformance test, the top example
② digital signature, or the top example. Just to see a fingerprint of MD5, press a handprint to explain the unique.
③ Secure access authentication, this is the usual system design problems.
When the user registers, the password is MD5 encrypted and stored in the database. This will prevent those who can see the database data, malicious operation.
MD5 can't crack it?
MD5 is irreversible, that is, there is no corresponding algorithm, from the production of MD5 value of the reverse to get the original data.
But if you use brute force, you say otherwise.
MD5 is the only one?
MD5 as the primary key in the database is it feasible? This involves a question, is the MD5 value unique? The answer is, not the only.
That is, a primitive data, which corresponds to only one MD5 value;
However, a MD5 value may correspond to multiple raw data.
Generate MD5 values in Java
Public classMd5test {//main test Class Public Static voidMain (string[] args) {String result= GetMD5 ("AAA"); SYSTEM.ERR.PRINTLN (result); } /*** Generate MD5 *@parammessage *@return */ Public Staticstring getMD5 (String message) {string Md5str= ""; Try { //1 Create an object that provides an information digest algorithm initialized to the MD5 algorithm objectMessageDigest MD = messagedigest.getinstance ("MD5"); //2 Turning the message into a byte array byte[] input =message.getbytes (); //3 calculate and get byte array, that's the 128 bits. byte[] Buff =md.digest (input); //4 Convert each byte of the array (eight bits per byte) into a 16 binary MD5 stringMd5str =Bytestohex (Buff); } Catch(Exception e) {e.printstacktrace (); } returnMd5str; } /*** Binary Turn hex *@parambytes *@return */ Public StaticString Bytestohex (byte[] bytes) {StringBuffer Md5str=NewStringBuffer (); //Convert Each byte of the array into a MD5 string of 16 binary intDigital; for(inti = 0; i < bytes.length; i++) {Digital=Bytes[i]; if(Digital < 0) {Digital+ = 256; } if(Digital < 16) {md5str.append ("0"); } md5str.append (Integer.tohexstring (digital)); } returnmd5str.tostring (). toUpperCase (); }}
MD5 's detailed algorithm ... Search for it yourself.
In addition, binary to 16 binary string:
PublicString Byte2hex (byte[] b) {StringBuffer buf=NewStringBuffer (""); String stmp= ""; for(intoffset = 0; Offset < b.length; offset++) {stmp= Integer.tohexstring (b[offset]&0XFF); if(stmp.length () = = 1) Buf.append ("0"). Append (STMP); Elsebuf.append (STMP); } returnbuf.tostring (); }
(Turn) Chat MD5