Java Cryptographic Decryption Message digest algorithm (MD5 SHA MAC)
Message digest
Message Digest, also known as a Digital digest (digitally Digest).
It is the only fixed-length value corresponding to a message or text that is generated by a one-way hash encryption function that acts on the message. Suppose the message changed on the way. The recipient is compared to the original digest by the newly generated digest of the received message. You can tell if the message has been changed. The message digest therefore guarantees the integrity of the message. The message digest uses a one-way hash function to encrypt the plaintext "digest" into a string of 128bit ciphertext. This cipher is also known as a digital fingerprint (Finger print), which has a fixed length. and different plaintext abstracts into ciphertext, the result is always different, and the same clear text of its abstract necessarily consistent. This sequence of abstracts can be used to verify whether the plaintext is a "true" fingerprint.
The anti-conflict nature of the hash function makes it possible to assume a slight change in the text, even if only one letter of the paragraph is changed, and a different value will be generated after the hash algorithm is applied.
The unidirectional nature of the hash algorithm makes it possible to find the same two different input messages to the hash value. It is impossible to calculate. So the hash value of the data. The message digest, which verifies the integrity of the data. Such an attribute of a hash function that produces different values for different inputs makes it impossible to find two inputs with the same hash value.
So. Assuming that two documents become the same value after a hash conversion, you can be sure that they are the same document. So. When you want to effectively compare two blocks, you can compare their hash values. Like what. The ability to verify that the message is being delivered is changed by comparing the hash value before and after the message is sent.
Message digest algorithm
The main feature of the Message digest algorithm is that the encryption process does not require a key, and the encrypted data cannot be decrypted, only the same plaintext data is entered by the same message digest algorithm ability to get the same ciphertext.
The message digest algorithm does not have the problem of key management and distribution, and it is suitable for distributed network. Because of the considerable amount of encryption calculations, the algorithms used to encrypt the data are usually only used for encryption with limited amounts. For example, a computer password is encrypted with an irreversible encryption algorithm. In recent years, with the rapid improvement of computer performance, the encryption speed is no longer a constraint to the development of encryption technology, so the field of message digest algorithm is added continuously.
Features of the Message digest algorithm:
① no matter how long the message is entered, the length of the computed message digest is always fixed.
The ② message digest appears to be "random".
These bits appear to have been randomly hashed together.
③ in general. Only the messages you want to enter are different, and the summary messages that are generated after they are summarized will not be the same, but the same input will produce the same output.
The ④ message digest function is a one-way function that does not have a trap, that is, it can only make a positive summary of the information, and cannot recover whatever message from the digest, or even find any information related to the original information at all.
⑤ a good digest algorithm. Two messages cannot be found, and their summaries are the same.
The existing message digest algorithm
The message digest algorithm includes the three series of MD, Sha and Mac. Often used to verify the integrity of data, is the core algorithm of data signature algorithm.
Unlike MD and SHA, Macs are hash function algorithms that contain keys. We also call the Mac an HMAC.
JDK support for message digest algorithms
JDK6 Support md2/md5/sha/sha256/sha384/sha512/hmacmd5/hmacsha1/hmacsha256/hmacsha384/hmacsha512
Using the 16 Binary tool class Hex.java see: Java byte array and hexadecimal string transfer
Java implementations of the MD and SHA series:
Digestutils.java
Java code
- import java.security.messagedigest;
- import java.security.nosuchalgorithmexception;
- Span style= "Color:black" >  
- /**
- Password Learn 4--java encryption decryption message digest algorithm (MD5 SHA MAC)