MD5 encryption MD5 decryption

Source: Internet
Author: User

  • #region MD5 Encryption
  • // <summary>
  • // MD5 encryption
  • // </summary>
  • /// <param name= "strsource" > string required for encryption </param>
  • /// <RETURNS>MD5 string after encryption </returns>
  • public static string Md5encrypt (string strsource)
  • {
  • //Put the string in a byte array
  • byte[] Bytin = System.Text.Encoding.Default.GetBytes (strsource);
  • //Establish keys and offsets for encrypted objects
  • Byte[] IV = {102, 16, 93, 156, 78, 4, 218, 32}; //define offset
  • byte[] key = {55, 103, 246, 79, 36, 99, 167, 3}; //define key
  • //Instance DES encryption class
  • DESCryptoServiceProvider mobjcryptoservice = new DESCryptoServiceProvider ();
  • Mobjcryptoservice.key = IV;
  • MOBJCRYPTOSERVICE.IV = key;
  • ICryptoTransform encrypto = Mobjcryptoservice.createencryptor ();
  • //instance MemoryStream stream encryption file
  • System.IO.MemoryStream ms = new System.IO.MemoryStream ();
  • CryptoStream cs = New CryptoStream (MS, Encrypto, CryptoStreamMode.Write);
  • Cs. Write (bytin, 0, bytin.length);
  • Cs. FlushFinalBlock ();
  • return System.Convert.ToBase64String (Ms.   ToArray ());
  • }  
  • #endregion
  • #region MD5 Decryption
  • // <summary>
  • /// MD5 decryption
  • // </summary>
  • /// <param name= "Source" > String to Decrypt </param>
  • /// <RETURNS>MD5 decrypted string </returns>
  • public static string Md5decrypt (string Source)
  • {
  • //Convert decrypted string to byte array
  • byte[] Bytin = System.Convert.FromBase64String (Source);
  • //Given the decrypted key and offset, the key and offset must be the same as the key and offset at the time of encryption
  • Byte[] IV = {102, 16, 93, 156, 78, 4, 218, 32}; //define offset
  • byte[] key = {55, 103, 246, 79, 36, 99, 167, 3}; //define key
  • DESCryptoServiceProvider mobjcryptoservice = new DESCryptoServiceProvider ();
  • Mobjcryptoservice.key = IV;
  • MOBJCRYPTOSERVICE.IV = key;
  • //instance stream for decryption
  • System.IO.MemoryStream ms = New System.IO.MemoryStream (bytin, 0, bytin.length);
  • ICryptoTransform encrypto = Mobjcryptoservice.createdecryptor ();
  • CryptoStream cs = New CryptoStream (MS, Encrypto, CryptoStreamMode.Read);
  • StreamReader STRD = new StreamReader (CS, Encoding.default);
  • return STRD.   ReadToEnd ();
  • }  
  • #endregion

MD5 encryption MD5 decryption

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.