Purpose of writing
Usually when we use cryptographic algorithms, we call a method directly, such as BASE64, to encrypt the string to be encrypted. For some algorithms that use a public private key, a maximum of a public key can be passed in. But when using the MD5 algorithm, it is always necessary to use a thing called digest, and then go through some mysterious code to the binary hex, in order to obtain the desired MD5 "encryption" results.
I used to use the MD5 encryption, I was puzzled, but just put someone else's written code to use, did not delve into the reasons, know it but do not know why. So take the time to figure out why and write down this article as a record.
MD5 is not encrypted at all.
The full name of MD5 is the MD5 message digest algorithm (MD5 message-digest algorithm), which is the fifth version of the Message digest algorithm. Therefore, the main purpose of MD5 is to verify the integrity of the message delivery, but does not hide the message content. The cryptographic algorithms we call daily are generally designed so that messages are not viewed or tampered with in the middle of the transmission, and that the message is received in a way that decrypts and views the entire original message.
In short, the encrypted information is complete, can be decrypted to get the original data, the summary of the information is incomplete, unable to restore the original data. So the MD5 algorithm and the encryption algorithm are not used in the same way. Strictly speaking, MD5 cannot be called a cryptographic algorithm.
What the hell is MD5 doing?
As the name implies, the message digest algorithm, "abstract" is one of the important steps, which also refers to the beginning of this article, the role of Digest.
The process of using MD5 in Java is as follows:
1. Create an object for the MD5 digest algorithm
MessageDigest MD = messagedigest.getinstance ("MD5");
2. Converting the string to be processed into a byte array
byte [] Bytemessage = Message.getbytes ();
3. Use the digest algorithm object to process the byte array and get a 128-bit digest byte array
byte [] buffer = md.digest (bytemessage);
4. Convert each byte of the array (one byte to eight bits) into a 16 binary to get the MD5 value of the original message
String md5str = bytestohex (buffer);
It can be seen from the above process that the processing process of MD5 algorithm is divided into two stages: abstract and concatenation of digest bytes into hexadecimal strings.
Summary
Figuring out the meaning of MD5, I also understand that MD5 and encryption have nothing to do with it. Later mention MD5, again will not be able to say "MD5 encryption" This kind of words come.
What is MD5, how to use a strange