3des加密算法的问题,急 我方系统要与平台集成,平台用一个加密算法,是3des,我在msdn文档里找到的3des加密算法都需要一个键和一个向量,可是平台之用一个string型的key实现的3des加密。.net 2003中如何实现之用一个键(如 “12345678”)的3des加密算法啊?急急急 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /// <summary> /// 加密 /// </summary> /// <param name="strString"></param> /// <param name="strKey"></param> /// <param name="encoding"></param> /// <returns></returns> public string Encrypt3DES(string strString, string strKey, Encoding encoding) { TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider(); MD5CryptoServiceProvider hashMD5 = new MD5CryptoServiceProvider(); DES.Key = hashMD5.ComputeHash(encoding.GetBytes(strKey)); DES.Mode = CipherMode.ECB; ICryptoTransform DESEncrypt = DES.CreateEncryptor(); byte[] Buffer = encoding.GetBytes(strString); return Convert.ToBase64String(DESEncrypt.TransformFinalBlock(Buffer, 0, Buffer.Length)); } /// <summary> /// 解密 /// </summary> /// <param name="strString"></param> /// <param name="strKey"></param> /// <returns></returns> public string Decrypt3DES(string strString, string strKey) { 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 ; }添加引用using System.Text;using System.Security;using System.Security.Cryptography; /// <summary> /// 加密 /// </summary> /// <param name="strString">要加密字符串</param> /// <param name="strKey">密钥</param> /// <param name="encoding">编码方式</param> /// <returns></returns> public string Encrypt3DES(string strString, string strKey, Encoding encoding) { TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider(); MD5CryptoServiceProvider hashMD5 = new MD5CryptoServiceProvider(); DES.Key = hashMD5.ComputeHash(encoding.GetBytes(strKey)); DES.Mode = CipherMode.ECB; ICryptoTransform DESEncrypt = DES.CreateEncryptor(); byte[] Buffer = encoding.GetBytes(strString); return Convert.ToBase64String(DESEncrypt.TransformFinalBlock(Buffer, 0, Buffer.Length)); } /// <summary> /// 解密 /// </summary> /// <param name="strString">要解密字符串</param> /// <param name="strKey">密钥</param> /// <returns></returns> public string Decrypt3DES(string strString, string strKey) { 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 ; } 可以用CAPICOM 这个ActiveX 来做. NickLee.Web.UI.Copyto 可以实现三倍DES加密www.cnblogs.com/mail-ricklee可以下载 如何通过webBrowser读取的本地html代码打开本地附件 c# winform richtextbox 插入文件选中后如何另存为原文件? 程序延时一段时间执行 一个经典的sql问题 axChartSpace 控件 求使用\b和\B的正则表达式示例 在BS中gridview 双击一行获取某一行的值, 短消息采用PDU模式发送,为什么总有部分字节数据对方接收不到(最后几个字节丢失)? 实现一个功能,帮帮忙。谢谢。散50分 求解winform界面诡异卡死的原因 正则 如何通过用户选定条件部署文件
/// 加密
/// </summary>
/// <param name="strString"></param>
/// <param name="strKey"></param>
/// <param name="encoding"></param>
/// <returns></returns>
public string Encrypt3DES(string strString, string strKey, Encoding encoding)
{
TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider hashMD5 = new MD5CryptoServiceProvider(); DES.Key = hashMD5.ComputeHash(encoding.GetBytes(strKey));
DES.Mode = CipherMode.ECB; ICryptoTransform DESEncrypt = DES.CreateEncryptor(); byte[] Buffer = encoding.GetBytes(strString);
return Convert.ToBase64String(DESEncrypt.TransformFinalBlock(Buffer, 0, Buffer.Length));
} /// <summary>
/// 解密
/// </summary>
/// <param name="strString"></param>
/// <param name="strKey"></param>
/// <returns></returns>
public string Decrypt3DES(string strString, string strKey)
{
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 ;
}
添加引用
using System.Text;
using System.Security;
using System.Security.Cryptography;
/// 加密
/// </summary>
/// <param name="strString">要加密字符串</param>
/// <param name="strKey">密钥</param>
/// <param name="encoding">编码方式</param>
/// <returns></returns>
public string Encrypt3DES(string strString, string strKey, Encoding encoding)
{
TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider hashMD5 = new MD5CryptoServiceProvider(); DES.Key = hashMD5.ComputeHash(encoding.GetBytes(strKey));
DES.Mode = CipherMode.ECB; ICryptoTransform DESEncrypt = DES.CreateEncryptor(); byte[] Buffer = encoding.GetBytes(strString);
return Convert.ToBase64String(DESEncrypt.TransformFinalBlock(Buffer, 0, Buffer.Length));
} /// <summary>
/// 解密
/// </summary>
/// <param name="strString">要解密字符串</param>
/// <param name="strKey">密钥</param>
/// <returns></returns>
public string Decrypt3DES(string strString, string strKey)
{
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 ;
}
可以实现三倍DES加密www.cnblogs.com/mail-ricklee可以下载