求C#的异或算法加密解密程序
展开全部
using System;
using System.Text;
using System.Security.Cryptography;
using System.IO;
namespace Server
{
public class PWD
{
/// <summary>
/// 执行DES加密
/// </summary>
public static string DesEncrypt(string mge)
{
string str = "";
if (!string.IsNullOrEmpty(mge))
{
try
{
byte[] MyStr_E = Encoding.UTF8.GetBytes(mge);
byte[] MyKey_E = Encoding.UTF8.GetBytes("*&^%$#@!");
DESCryptoServiceProvider MyDes_E = new DESCryptoServiceProvider();
MyDes_E.Key = MyKey_E;
MyDes_E.IV = MyKey_E;
MemoryStream MyMem_E = new MemoryStream();
CryptoStream MyCry_E = new CryptoStream(MyMem_E, MyDes_E.CreateEncryptor(), CryptoStreamMode.Write);
MyCry_E.Write(MyStr_E, 0, MyStr_E.Length);
MyCry_E.Flush();
MyCry_E.Close();
str = Convert.ToBase64String(MyMem_E.ToArray());
MyMem_E.Close();
}
catch (Exception)
{
}
}
return str;
}
/// <summary>
/// 执行DES解密
/// </summary>
public static string DesDecrypt(string mge)
{
string str = "";
if (!string.IsNullOrEmpty(mge))
{
try
{
byte[] MyStr_D = Convert.FromBase64String(mge);
byte[] MyKey_D = Encoding.UTF8.GetBytes("*&^%$#@!");
DESCryptoServiceProvider MyDes_D = new DESCryptoServiceProvider();
MyDes_D.Key = MyKey_D;
MyDes_D.IV = MyKey_D;
MemoryStream MyMem_D = new MemoryStream();
CryptoStream MyCry_D = new CryptoStream(MyMem_D, MyDes_D.CreateDecryptor(), CryptoStreamMode.Write);
MyCry_D.Write(MyStr_D, 0, MyStr_D.Length);
MyCry_D.Flush();
MyCry_D.Close();
str = Encoding.UTF8.GetString(MyMem_D.ToArray());
MyMem_D.Close();
}
catch (Exception)
{
}
}
return str;
}
}
}
using System.Text;
using System.Security.Cryptography;
using System.IO;
namespace Server
{
public class PWD
{
/// <summary>
/// 执行DES加密
/// </summary>
public static string DesEncrypt(string mge)
{
string str = "";
if (!string.IsNullOrEmpty(mge))
{
try
{
byte[] MyStr_E = Encoding.UTF8.GetBytes(mge);
byte[] MyKey_E = Encoding.UTF8.GetBytes("*&^%$#@!");
DESCryptoServiceProvider MyDes_E = new DESCryptoServiceProvider();
MyDes_E.Key = MyKey_E;
MyDes_E.IV = MyKey_E;
MemoryStream MyMem_E = new MemoryStream();
CryptoStream MyCry_E = new CryptoStream(MyMem_E, MyDes_E.CreateEncryptor(), CryptoStreamMode.Write);
MyCry_E.Write(MyStr_E, 0, MyStr_E.Length);
MyCry_E.Flush();
MyCry_E.Close();
str = Convert.ToBase64String(MyMem_E.ToArray());
MyMem_E.Close();
}
catch (Exception)
{
}
}
return str;
}
/// <summary>
/// 执行DES解密
/// </summary>
public static string DesDecrypt(string mge)
{
string str = "";
if (!string.IsNullOrEmpty(mge))
{
try
{
byte[] MyStr_D = Convert.FromBase64String(mge);
byte[] MyKey_D = Encoding.UTF8.GetBytes("*&^%$#@!");
DESCryptoServiceProvider MyDes_D = new DESCryptoServiceProvider();
MyDes_D.Key = MyKey_D;
MyDes_D.IV = MyKey_D;
MemoryStream MyMem_D = new MemoryStream();
CryptoStream MyCry_D = new CryptoStream(MyMem_D, MyDes_D.CreateDecryptor(), CryptoStreamMode.Write);
MyCry_D.Write(MyStr_D, 0, MyStr_D.Length);
MyCry_D.Flush();
MyCry_D.Close();
str = Encoding.UTF8.GetString(MyMem_D.ToArray());
MyMem_D.Close();
}
catch (Exception)
{
}
}
return str;
}
}
}
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询