字符串加解密? 要求:加密前的字符串为8位,如:"hdfy0987"加密后的字符串仍为8位;解密后的字符串仍然为:"hdfy0987"谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.cnblogs.com/weekzero/archive/2007/12/05/983143.html/// <summary> /// 进行DES加密。 /// </summary> /// <param name="pToEncrypt">要加密的字符串。</param> /// <param name="sKey">密钥,且必须为8位。</param> /// <returns>以Base64格式返回的加密字符串。</returns> public string Encrypt(string pToEncrypt, string sKey) { using (DESCryptoServiceProvider des = new DESCryptoServiceProvider()) { byte[] inputByteArray = Encoding.UTF8.GetBytes(pToEncrypt); des.Key = ASCIIEncoding.ASCII.GetBytes(sKey); des.IV = ASCIIEncoding.ASCII.GetBytes(sKey); System.IO.MemoryStream ms = new System.IO.MemoryStream(); using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write)) { cs.Write(inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock(); cs.Close(); } string str = Convert.ToBase64String(ms.ToArray()); ms.Close(); return str; } } /**//// <summary> /// 进行DES解密。 /// </summary> /// <param name="pToDecrypt">要解密的以Base64</param> /// <param name="sKey">密钥,且必须为8位。</param> /// <returns>已解密的字符串。</returns> public string Decrypt(string pToDecrypt, string sKey) { byte[] inputByteArray = Convert.FromBase64String(pToDecrypt); using (DESCryptoServiceProvider des = new DESCryptoServiceProvider()) { des.Key = ASCIIEncoding.ASCII.GetBytes(sKey); des.IV = ASCIIEncoding.ASCII.GetBytes(sKey); System.IO.MemoryStream ms = new System.IO.MemoryStream(); using (CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write)) { cs.Write(inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock(); cs.Close(); } string str = Encoding.UTF8.GetString(ms.ToArray()); ms.Close(); return str; } } //调用string str = "hdfy0987";string code = Encrypt(str,"88888888");//加密string newstr = Decrypt(code,"88888888");//还原 DESCryptoServiceProvider des = new DESCryptoServiceProvider()这个对象的要求吧,你可以查下 查了一下貌似是的,有这么句话:于数据加密标准 (DES) 将等于 8 个字节或 8 个字符的 64 位密钥。8位就8位吧,不纠结这个问题了~ Des是私钥加密的。这个是用于双方约定了一个私钥进行加密的。如果要多位的对称加密。可以用128位分组对称加密算法:AES c#下256位密码的AES加解密函数原型C#中使用DES和AES加密解密 加密解密方法很多如des,sha,rsa等主要是密钥http://topic.csdn.net/u/20090110/13/e28ea3f1-ff3a-4cc9-84b6-18e4e426b46f.html 有做过单点登录的吗?给介绍下怎么做,多谢 请问下一般服务端异常问题? 请教如何在同一个textbox中连续两次取值 百思不得其解,请问下面这个效果如何实现? C#打包DLL不自动注册!!!!急~!! OracleClient客户端NLS_LANG设置为AMERICAN_AMERICA。。。结果中文乱码 双击第三方控件SideBar的列表项如何获得列表项的Tag值 很急的一个问题,请问如何用C#产生条码,并且能打印出来,谢谢,感激不尽 安装ActiveReports的问题 一个 silverlight 游戏地图的问题 懂组建局域网的 ,请进来指点一下 imageList获取图片的名称
/// 进行DES加密。
/// </summary>
/// <param name="pToEncrypt">要加密的字符串。</param>
/// <param name="sKey">密钥,且必须为8位。</param>
/// <returns>以Base64格式返回的加密字符串。</returns>
public string Encrypt(string pToEncrypt, string sKey)
{
using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
{
byte[] inputByteArray = Encoding.UTF8.GetBytes(pToEncrypt);
des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write))
{
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
cs.Close();
}
string str = Convert.ToBase64String(ms.ToArray());
ms.Close();
return str;
}
} /**//// <summary>
/// 进行DES解密。
/// </summary>
/// <param name="pToDecrypt">要解密的以Base64</param>
/// <param name="sKey">密钥,且必须为8位。</param>
/// <returns>已解密的字符串。</returns>
public string Decrypt(string pToDecrypt, string sKey)
{
byte[] inputByteArray = Convert.FromBase64String(pToDecrypt);
using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
{
des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
using (CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write))
{
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
cs.Close();
}
string str = Encoding.UTF8.GetString(ms.ToArray());
ms.Close();
return str;
}
} //调用
string str = "hdfy0987";
string code = Encrypt(str,"88888888");//加密
string newstr = Decrypt(code,"88888888");//还原
这个对象的要求吧,你可以查下
于数据加密标准 (DES) 将等于 8 个字节或 8 个字符的 64 位密钥。
8位就8位吧,不纠结这个问题了~
主要是密钥
http://topic.csdn.net/u/20090110/13/e28ea3f1-ff3a-4cc9-84b6-18e4e426b46f.html