天目网

设置首页 - 加入收藏
首页   女人情感   投资理财   大众美食   宠物乐园   娱乐八卦   电视剧情介绍   电脑技术
 

C#实现3DES加密24位密钥-程序员天空

2008-5-7 19:59:27 来源:本站
 
新一篇:.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();
}
}
}
相关文章
·暂无
feedsky
抓虾
pageflakes
Rojo
google reader
netvibes
my yahoo
newsgator
bloglines
鲜果
哪吒
有道