usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Security.Cryptography;usingSystem.Text;namespacetestweb{ Public classDesencrypt {#region======== Encryption ========/// <summary> ///Encrypt/// </summary> /// <param name= "Text" ></param> /// <returns></returns> Public Static stringEncrypt (stringText) { returnEncrypt (Text,"Test"); } /// <summary> ///Encrypt Data/// </summary> /// <param name= "Text" ></param> /// <param name= "SKey" ></param> /// <returns></returns> Public Static stringEncrypt (stringText,stringSKey) {DESCryptoServiceProvider des=NewDESCryptoServiceProvider (); byte[] inputbytearray; Inputbytearray=Encoding.Default.GetBytes (Text); Des. Key= ASCIIEncoding.ASCII.GetBytes (System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (SKey,"MD5"). Substring (0,8)); Des.iv= ASCIIEncoding.ASCII.GetBytes (System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (SKey,"MD5"). Substring (0,8)); System.IO.MemoryStream Ms=NewSystem.IO.MemoryStream (); CryptoStream CS=NewCryptoStream (MS, Des. CreateEncryptor (), cryptostreammode.write); Cs. Write (Inputbytearray,0, inputbytearray.length); Cs. FlushFinalBlock (); StringBuilder ret=NewStringBuilder (); foreach(byteBinchMs. ToArray ()) {ret. AppendFormat ("{0:x2}", B); } returnret. ToString (); } #endregion #region======== Decryption ========/// <summary> ///decryption/// </summary> /// <param name= "Text" ></param> /// <returns></returns> Public Static stringDecrypt (stringText) { returnDecrypt (Text,"Test"); } /// <summary> ///Decrypt Data/// </summary> /// <param name= "Text" ></param> /// <param name= "SKey" ></param> /// <returns></returns> Public Static stringDecrypt (stringText,stringSKey) {DESCryptoServiceProvider des=NewDESCryptoServiceProvider (); intLen; Len= Text.length/2; byte[] Inputbytearray =New byte[Len]; intx, I; for(x =0; x < Len; X + +) {i= Convert.ToInt32 (text.substring (x *2,2), -); INPUTBYTEARRAY[X]= (byte) I; } des. Key= ASCIIEncoding.ASCII.GetBytes (System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (SKey,"MD5"). Substring (0,8)); Des.iv= ASCIIEncoding.ASCII.GetBytes (System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (SKey,"MD5"). Substring (0,8)); System.IO.MemoryStream Ms=NewSystem.IO.MemoryStream (); CryptoStream CS=NewCryptoStream (MS, Des. CreateDecryptor (), cryptostreammode.write); Cs. Write (Inputbytearray,0, inputbytearray.length); Cs. FlushFinalBlock (); returnEncoding.Default.GetString (Ms. ToArray ()); } #endregion }}
C # program password with DES encryption source code