VSC#2013DES加密解密完整源代码测试平台visualstudio2013win8.1依据网上资源整理,并亲测,并写出窗口供调用演示,原代码全部打包奉上,可供学习使用。
publicstaticstringEncryptDES(stringencryptString,stringencryptKey){try{byte[]rgbKey=Encoding.UTF8.GetBytes(encryptKey.Substring(0,8));byte[]rgbIV=Keys;byte[]inputByteArray=Encoding.UTF8.GetBytes(encryptString);DESCryptoServiceProviderdCSP=newDESCryptoServiceProvider();MemoryStreammStream=newMemoryStream();CryptoStreamcStream=newCryptoStream(mStream,dCSP.CreateEncryptor(rgbKey,rgbIV),CryptoStreamMode.Write);cStream.Write(inputByteArray,0,inputByteArray.Length);cStream.FlushFinalBlock();returnConvert.ToBase64String(mStream.ToArray());}catch{returnencryptString;}}////DES解密字符串////待解密的字符串//解密密钥,要求为8位,和加密密钥相同//解密成功前往解密后的字符串,失败返源串publicstaticstringDecryptDES(stringdecryptString,stringdecryptKey){try{byte[]rgbKey=Encoding.UTF8.GetBytes(decryptKey);byte[]rgbIV=Keys;byte[]inputByteArray=Convert.FromBase64String(decryptString);DESCryptoServiceProviderDCSP=newDESCryptoServiceProvider();MemoryStreammStream=newMemoryStream();CryptoStreamcStream=newCryptoStream(mStream,DCSP.CreateDecryptor(rgbKey,rgbIV),CryptoStreamMode.Write);cStream.Write(inputByteArray,0,inputByteArray.Length);cStream.FlushFinalBlock();returnEncoding.UTF8.GetString(mStream.ToArray());}catch{returndecryptString;}}
1