在.net中运用了sha1加密算法.
但是现在用c#.net进行sha1加密算法.得到的结果不一样.请问这是算法有问题还是本身算出的结果就不一样...
C#算法 string Pwd = PassWord.Text;
byte[] data = System.Text.Encoding.Default.GetBytes(Pwd);//以字节方式存储
System.Security.Cryptography.SHA1 sha1 = new Security.Cryptography.SHA1CryptoServiceProvider();
byte[] result = sha1.ComputeHash(data);//得到哈希值
string res = Convert.ToBase64String(result); //转换成为字符串的显示C#.net算法string Pwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(PassWord.Text, "SHA1");谢谢各位帮帮忙解答
如果各位有好的方法也不妨说说,但是我想在加密后的结果都是统一的....
但是现在用c#.net进行sha1加密算法.得到的结果不一样.请问这是算法有问题还是本身算出的结果就不一样...
C#算法 string Pwd = PassWord.Text;
byte[] data = System.Text.Encoding.Default.GetBytes(Pwd);//以字节方式存储
System.Security.Cryptography.SHA1 sha1 = new Security.Cryptography.SHA1CryptoServiceProvider();
byte[] result = sha1.ComputeHash(data);//得到哈希值
string res = Convert.ToBase64String(result); //转换成为字符串的显示C#.net算法string Pwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(PassWord.Text, "SHA1");谢谢各位帮帮忙解答
如果各位有好的方法也不妨说说,但是我想在加密后的结果都是统一的....
解决方案 »
- WPF高手指点迷津:这种动画该怎么做?
- 请问windows窗体可否像QQ一样运行时在电脑右下角显示
- 我写了个xml的创建和访问的类,请大家给点意见
- 本地机器上的两个进程,互相发一些短的消息,请问用哪种通信方式好呢?匿名管道,命名管道还是消息机制?原因是什么?好实现吗?
- 并于sql并发时间问题
- WPF中关于ListView的问题
- 问下:大家在做页面的时候习惯写html源代码还是喜欢在设计界面里拖动控件或修改控件属性?
- 如何把一个类分在两个文件里写?
- 用OLEDB打开excel文件遇到的问题?????????
- 如何在.net通过代码来给xml指定schema,急,请大家帮忙
- ColorDialog怎么控制显示位置
- 两个函数间值传递
------
一样才见鬼...去查查Base64编码是怎么回事儿...
你确定它们一样吗?
(用System.BitConverter.ToString())class A
{
static string GetPwd(string Pwd)
{
byte[] data = System.Text.Encoding.Default.GetBytes(Pwd);//以字节方式存储
System.Security.Cryptography.SHA1 sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
byte[] result = sha1.ComputeHash(data);//得到哈希值
return System.BitConverter.ToString(result).Replace("-", ""); //转换成为字符串的显示
} static void Main()
{
string input = "ABCD";
string Pwd1 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(input, "SHA1");
System.Console.WriteLine(Pwd1);
string Pwd2 = GetPwd(input);
System.Console.WriteLine(Pwd2);
}
}/* 程序输出:
FB2F85C88567F3C8CE9B799C7C54642D0C7B41F6
FB2F85C88567F3C8CE9B799C7C54642D0C7B41F6
*/
全部用你的方法,而不用HashPasswordForStoringInConfigFile。
用5楼的方法:
string res = System.BitConverter.ToString(result).Replace("-", ""); //转换成为字符串的显示