Des encryption uses DESCryptoServiceProvider encryption. DESCryptoServiceProvider under the namespace: System.Security.Cryptography;
The advantages of symmetric encryption algorithms are the high speed of decryption and the difficulty of cracking when using long keys. Assuming that two users need to encrypt and then exchange data using a symmetric encryption method, the user needs at least 2 keys and is exchanged, and if there are N in the enterprise, the entire enterprise needs NX (n-1) keys, and the generation and distribution of the keys will become the nightmare of the Enterprise Information Department. The security of the symmetric encryption algorithm depends on the storage of the encryption key, but it is impossible for everyone in the enterprise to keep a secret, and they usually leak the key out-if a user uses a key that is obtained by the intruder, the intruder can read all the documents encrypted by the user key. If a single encryption key is shared across the enterprise, the confidentiality of the entire enterprise document will not be discussed
Des encryption can be decrypted.
1 /// <summary> 2 ///des decryption Data3 /// </summary> 4 /// <param name= "Text" ></param> 5 /// <param name= "SKey" ></param> 6 /// <returns></returns> 7 Public Static stringDecrypt (stringText,stringSKey)8 {9DESCryptoServiceProvider des =NewDESCryptoServiceProvider ();Ten intLen; OneLen = text.length/2; A byte[] Inputbytearray =New byte[Len]; - intx, I; - for(x =0; x < Len; X + +) the { -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 (); ACryptoStream cs =NewCryptoStream (MS, Des. CreateDecryptor (), cryptostreammode.write); atCs. Write (Inputbytearray,0, inputbytearray.length); - cs. FlushFinalBlock (); - returnEncoding.Default.GetString (Ms. ToArray ()); - } - - #endregion in /// <summary> - ///des encrypted Data to /// </summary> + /// <param name= "Text" ></param> - /// <param name= "SKey" ></param> the /// <returns></returns> * Public Static stringEncrypt (stringText,stringSKey) $ {Panax Notoginseng //DESCryptoServiceProvider namespace: System.Security.Cryptography; -DESCryptoServiceProvider des =NewDESCryptoServiceProvider (); the byte[] inputbytearray; +Inputbytearray =Encoding.Default.GetBytes (Text); A //FormsAuthentication namespace: System.Web.Security; theDes. Key = ASCIIEncoding.ASCII.GetBytes (FormsAuthentication.HashPasswordForStoringInConfigFile (SKey,"MD5"). Substring (0,8)); +DES.IV = ASCIIEncoding.ASCII.GetBytes (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 (); the foreach(byteBinchMs. ToArray ()) - {WuyiRet. AppendFormat ("{0:x2}", b); the } - returnret. ToString (); Wu}
This can be called
1 /// <summary>2 ///Encrypt3 /// </summary>4 /// <param name= "Text" ></param>5 /// <returns></returns>6 Public Static stringEncrypt (stringText)7 {8 returnEncrypt (Text,"Unity3d");9 }Ten /// <summary> One ///decryption A /// </summary> - /// <param name= "Text" ></param> - /// <returns></returns> the Public Static stringDecrypt (stringText) - { - returnDecrypt (Text,"Unity3d"); -}
Des encryption of data encryption