First
I have seen a lot of posts on topics such as MD5 encryption and decryption. Therefore, I wrote this article to give you a thorough explanation of the MD5 encryption problem and give you the code that has been practiced.
Second
MD5 encryption does not encrypt the original text. You must note that since the original text is not encrypted, why? It's a joke. The purpose of MD5 is to generate 16-byte ciphertext based on a certain algorithm for a piece of original data. Through this ciphertext, we can check whether the original data has been modified. It is often used for plain text data transmission in the network to prevent malicious modification of content during transmission. The typical application protocol is radius, and the RADIUS protocol contains 16 bytes of MD5, which adds the user's password to the end of the message for MD5 and stores the result in the network, therefore, the plaintext part does not see the user's password. When the server receives this packet, it uses the same MD5 method. If the encrypted 16-byte is the same, it indicates that it is a valid network packet that has not been maliciously modified.
Last
Attached implementation code
-
- ImportJava. Security .*;
-
- Public ClassMD5 {
- /**
- * MD5
- *
- * @ Author dreamer
- */
- PublicMD5 (){
- }
-
- Public Static Byte[] MD5 (Byte[] In ){
- MessagedigestMD =Null;
- Byte[] Out =New Byte[16];
- Try{
- MD =Messagedigest. Getinstance ("MD5 ");
- }
- Catch(NosuchalgorithmexceptionEx ){
- System. Out. println (ex. tostring ());
- }
- Md. Reset ();
- Md. Update (in );
- Out = md. Digest ();
- ReturnOut;
- }
-
- Public Static Byte[] MD5 (Byte[] In,IntLen ){
- MessagedigestMD =Null;
- Byte[] Out =New Byte[16];
- Try{
- MD =Messagedigest. Getinstance ("MD5 ");
- }
- Catch(NosuchalgorithmexceptionEx ){
- System. Out. println (ex. tostring ());
- }
- Md. Reset ();
- Md. Update (in, 0, Len );
- Out = md. Digest ();
- ReturnOut;
- }
-
- }