新一篇:.NET中class和struct的区别usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
usingSystem.IO;
usingSystem.Security.Cryptography;
namespaceConsoleApplication1
{
classProgram
{
publicstaticstringEncrypt3DES(stringa_strString,stringa_strKey)
{
TripleDESCryptoServiceProviderDES=newTripleDESCryptoServiceProvider();
DES.Key=ASCIIEncoding.ASCII.GetBytes(a_strKey);
DES.Mode=CipherMode.ECB;
ICryptoTransformDESEncrypt=DES.CreateEncryptor();
byte[]Buffer=ASCIIEncoding.ASCII.GetBytes(a_strString);
returnConvert.ToBase64String(DESEncrypt.TransformFinalBlock(Buffer,0,Buffer.Length));
}
publicstaticstringDecrypt3DES(stringa_strString,stringa_strKey)
{
TripleDESCryptoServiceProviderDES=newTripleDESCryptoServiceProvider();
DES.Key=ASCIIEncoding.ASCII.GetBytes(a_strKey);
DES.Mode=CipherMode.ECB;
DES.Padding=System.Security.Cryptography.PaddingMode.PKCS7;
ICryptoTransformDESDecrypt=DES.CreateDecryptor();
stringresult="";
try
{
byte[]Buffer=Convert.FromBase64String(a_strString);
result=ASCIIEncoding.ASCII.GetString(DESDecrypt.TransformFinalBlock(Buffer,0,Buffer.Length));
}
catch(Exceptione)
{
}
returnresult;
}
staticvoidMain(string[]args)
{
Console.WriteLine(Encrypt3DES("999999999","#s^un2ye31<cn|aoXpR, vh");
Console.ReadLine();
}
}
}