I/O and network-MD5 encryption and JAVA Implementation

Source: Internet
Author: User

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

  1.  
  2. ImportJava. Security .*;
  3.  
  4. Public ClassMD5 {
  5. /**
  6. * MD5
  7. *
  8. * @ Author dreamer
  9. */
  10. PublicMD5 (){
  11. }
  12.  
  13. Public Static Byte[] MD5 (Byte[] In ){
  14. MessagedigestMD =Null;
  15. Byte[] Out =New Byte[16];
  16. Try{
  17. MD =Messagedigest. Getinstance ("MD5 ");
  18. }
  19. Catch(NosuchalgorithmexceptionEx ){
  20. System. Out. println (ex. tostring ());
  21. }
  22. Md. Reset ();
  23. Md. Update (in );
  24. Out = md. Digest ();
  25. ReturnOut;
  26. }
  27.  
  28. Public Static Byte[] MD5 (Byte[] In,IntLen ){
  29. MessagedigestMD =Null;
  30. Byte[] Out =New Byte[16];
  31. Try{
  32. MD =Messagedigest. Getinstance ("MD5 ");
  33. }
  34. Catch(NosuchalgorithmexceptionEx ){
  35. System. Out. println (ex. tostring ());
  36. }
  37. Md. Reset ();
  38. Md. Update (in, 0, Len );
  39. Out = md. Digest ();
  40. ReturnOut;
  41. }
  42.  
  43. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.