using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Security.Cryptography;//加密
using System.Text;
/// <summary>
/// Code 的摘要說明
/// </summary>
public class Code
{
public Code()
{
//
// TODO: 在此處添加構造函數邏輯
//
}
//3des加密
public string Encrypt3DES(string strString)
{
string strKey = "malong";
TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider hashMD5 = new MD5CryptoServiceProvider();
DES.Key = hashMD5.ComputeHash(Encoding.ASCII.GetBytes(strKey));
DES.Mode = CipherMode.ECB;
ICryptoTransform DESEncrypt = DES.CreateEncryptor();
byte[] Buffer = Encoding.ASCII.GetBytes(strString);
return Convert.ToBase64String(DESEncrypt.TransformFinalBlock(Buffer, 0, Buffer.Length));
}
//解密
public string Decrypt3DES(string strString)
{
string strKey = "malong";
TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider hashMD5 = new MD5CryptoServiceProvider();
DES.Key = hashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(strKey));
DES.Mode = CipherMode.ECB;
ICryptoTransform DESDecrypt = DES.CreateDecryptor();
string result = "";
try
{
byte[] Buffer = Convert.FromBase64String(strString);
result = ASCIIEncoding.ASCII.GetString(DESDecrypt.TransformFinalBlock(Buffer, 0, Buffer.Length));
}
catch (System.Exception e)
{
throw (new System.Exception("null", e));
}
return result;
}
//md5加密
public string EncryptMD5(string str)
{
MD5CryptoServiceProvider hashMD5 = new MD5CryptoServiceProvider();
string s=ASCIIEncoding.ASCII.GetString(hashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(str)));
return s;
}
}