using System;
using System.Text;
using System.Security.Cryptography;
using System.IO;
namespace Server
{
public class PWD
{
///
/// 执行DES加密
///
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;
}
///
/// 执行DES解密
///
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;
}
}
}
去网上搜一下吧,应该有的