. Net md5 Encryption

Source: Internet
Author: User
  1. UsingSystem;
  2. UsingSystem. Data;
  3. UsingSystem. Configuration;
  4. UsingSystem. Collections;
  5. UsingSystem. Web;
  6. UsingSystem. Web. Security;
  7. UsingSystem. Web. UI;
  8. UsingSystem. Web. UI. WebControls;
  9. UsingSystem. Web. UI. WebControls. WebParts;
  10. UsingSystem. Web. UI. HtmlControls;
  11. UsingOA online. BLL;
  12. UsingSystem. Diagnostics;
  13. UsingSystem. Text;
  14. UsingSystem. Security. Cryptography;
  15. UsingSystem. IO;
  16. // 1. encrypted to a 32-bit hexadecimal string
  17. Protected StringHashMD5_String (StringStr)
  18. {
  19. ReturnFormsAuthentication. HashPasswordForStoringInConfigFile (str, "MD5"). ToLower ();
  20. }
  21. // 2. Same as above, increase the offset
  22. Public StringGetMD5 (StringSDataIn,StringMove)
  23. {
  24. System. Security. Cryptography. MD5CryptoServiceProvider md5 =NewSystem. Security. Cryptography. MD5CryptoServiceProvider ();
  25. Byte[] Byt, bytHash;
  26. Byt = System. Text. Encoding. UTF8.GetBytes (move + sDataIn );
  27. BytHash = md5.ComputeHash (byt );
  28. Md5.Clear ();
  29. StringSTemp = "";
  30. For(IntI = 0; I <bytHash. Length; I ++)
  31. {
  32. STemp + = bytHash [I]. ToString ("x"). PadLeft (2, '0 ');
  33. }
  34. ReturnSTemp;
  35. }
  36. // 3. encode the string into an ASCII array and then encrypt it with MD5.
Using System; using System. data; using System. configuration; using System. collections; using System. web; using System. web. security; using System. web. UI; using System. web. UI. webControls; using System. web. UI. webControls. webParts; using System. web. UI. htmlControls; using OAOnline. BLL; using System. diagnostics; using System. text; using System. security. cryptography; using System. IO; // 1. encrypted to a 32-bit hexadecimal string protected string HashMD5_String (string str) {return FormsAuthentication. hashPasswordForStoringInConfigFile (str, "MD5 "). toLower ();} // 2. Same as above, add the offset public string GetMD5 (string sDataIn, string move) {System. security. cryptography. MD5CryptoServiceProvider md5 = new System. security. cryptography. MD5CryptoServiceProvider (); byte [] byt, bytHash; byt = System. text. encoding. UTF8.GetBytes (move + sDataIn); bytHash = md5.ComputeHash (byt); md5.Clear (); string sTemp = ""; for (int I = 0; I <bytHash. length; I ++) {sTemp + = bytHash [I]. toString ("x "). padLeft (2, '0');} return sTemp;} // 3. encode the string into an ASCII array and then encrypt it with MD5.
C # code
  1. Public static string MD5Encrypt (string strEnc)
  2. {
  3. String str = "encryption failed! ";
  4. Try
  5. {
  6. System. Security. Cryptography. MD5CryptoServiceProvider MD5 = new System. Security. Cryptography. MD5CryptoServiceProvider ();
  7. Str = ASCIIEncoding. ASCII. GetString (MD5.ComputeHash (ASCIIEncoding. ASCII. GetBytes (strEnc )));
  8. Return str;
  9. }
  10. Catch (System. Exception ex)
  11. {
  12. Throw (ex );
  13. }
  14. }

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.