请问我这段程序为什么每次得到得return出来的值都不样呢,有什么问题呢。其中传人key的值为"02258"
public string GetICPDESPassword(string key)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
ICryptoTransform cc = des.CreateEncryptor();
byte[] _output = System.Text.Encoding.Default.GetBytes(key);
des.Mode = CipherMode.ECB;
des.Key =getKey(_output);
return HttpUtility.UrlEncode(cc.TransformFinalBlock(_output,0,_output.Length));
}
private byte[] getKey(byte[] arrBTmp)
{
byte[] arrB = new byte[8];
//将原始字节数组转换为8位
for (int i = 0; i < arrBTmp.Length && i < arrB.Length; i++)
{
arrB[i] = arrBTmp[i];
} //生成密钥
return arrB;
}
public string GetICPDESPassword(string key)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
ICryptoTransform cc = des.CreateEncryptor();
byte[] _output = System.Text.Encoding.Default.GetBytes(key);
des.Mode = CipherMode.ECB;
des.Key =getKey(_output);
return HttpUtility.UrlEncode(cc.TransformFinalBlock(_output,0,_output.Length));
}
private byte[] getKey(byte[] arrBTmp)
{
byte[] arrB = new byte[8];
//将原始字节数组转换为8位
for (int i = 0; i < arrBTmp.Length && i < arrB.Length; i++)
{
arrB[i] = arrBTmp[i];
} //生成密钥
return arrB;
}
解决方案 »
- 如何设定GridView的某一列绑定到DropDownList?
- 急~~水晶报表使用推模式,SetDataSource后还是无数据
- Gridview有DropDownList作为查询条件问题
- 北京软件公司 招聘.net开发人员
- 关于dropdownlist和datagrid的问题。。。拜托路过的老大们能进来下啊~~~~~
- 如何在绑定TreeView的时候过滤XML中的根节点
- 关于Method NOT Allowed
- 急,快来帮帮忙
- 经典解决方案:在ASP.NET中存取Word文档
- 问一个100分的数据库问题!!!!!!!!!!!!!!!
- 请看这样一个问题~````
- asp.net上传文件的权限问题(xp中)
看一下这个
看看微软给的说明:如果当前的 Key 为空引用(Visual Basic 中为 Nothing),则将调用 GenerateKey 创建新的随机 Key。如果当前的 IV 为空引用 (Nothing),则将调用 GenerateIV 创建新的随机 IV。使用具有相同签名的 CreateDecryptor 重载来解密此方法的结果。很明显在调用这个方法的时候,KEY和IV都没有。所以两者都是随机的。改为:
DESCryptoServiceProvider des = new DESCryptoServiceProvider(); des.Mode = CipherMode.ECB;
byte[] _output = System.Text.Encoding.Default.GetBytes(key);
des.Key =getKey(_output);ICryptoTransform cc = des.CreateEncryptor();
就没有问题了!