求一段C#简单的字符串加密与解密代码
来源:百度知道 编辑:UC知道 时间:2024/08/20 08:27:49
using System.Security.Cryptography;
using System.Text;
string get6(string 要加密的文字或者要解密的文字outXMLFilePath, string jia)
{
byte[] Keys ={ 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
if (jia.Equals("加密"))
{
byte[] rgbKey ={ 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
byte[] rgbIV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
byte[] inputByteArray = Encoding.UTF8.GetBytes(outXMLFilePath);
DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();
MemoryStream mStream = new MemoryStream();
CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
cStream.Write(inputByteArray, 0, inputByteArray.Length);
cStream.FlushFinalBlock();
return Convert.ToBase64String(mStream.ToArray());