using System; using System.Security.Cryptography; using System.Text; using System.IO; namespace Common ... {/**////<summary>///DESEncrypt加密解密算法。///</summary>publicsealedclassDESEncrypt...{privateDESEncrypt()...{////TODO:在此处添加构造函数逻辑//}privatestaticstringkey="zhoufoxcn";/**////<summary>///对称加密解密的密钥///</summary>publicstaticstringKey...{get...{returnkey;}set...{key=value;}}/**////<summary>///DES加密///</summary>///<paramname="encryptString"></param>///<returns></returns>publicstaticstringDesEncrypt(stringencryptString)...{byte[]keyBytes=Encoding.UTF8.GetBytes(key.Substring(0,8));byte[]keyIV=keyBytes;byte[]inputByteArray=Encoding.UTF8.GetBytes(encryptString);DESCryptoServiceProviderprovider=newDESCryptoServiceProvider();MemoryStreammStream=newMemoryStream();CryptoStreamcStream=newCryptoStream(mStream,provider.CreateEncryptor(keyBytes,keyIV),CryptoStreamMode.Write);cStream.Write(inputByteArray,0,inputByteArray.Length);cStream.FlushFinalBlock();returnConvert.ToBase64String(mStream.ToArray());}/**////<summary>///DES解密///</summary>///<paramname="decryptString"></param>///<returns></returns>publicstaticstringDesDecrypt(stringdecryptString)...{byte[]keyBytes=Encoding.UTF8.GetBytes(key.Substring(0,8));byte[]keyIV=keyBytes;byte[]inputByteArray=Convert.FromBase64String(decryptString);DESCryptoServiceProviderprovider=newDESCryptoServiceProvider();MemoryStreammStream=newMemoryStream();CryptoStreamcStream=newCryptoStream(mStream,provider.CreateDecryptor(keyBytes,keyIV),CryptoStreamMode.Write);cStream.Write(inputByteArray,0,inputByteArray.Length);cStream.FlushFinalBlock();returnEncoding.UTF8.GetString(mStream.ToArray());}}}