检查您是否正确结束该行,或者使用尾部“|”或删除不必要的尾部'|'。
还要检查您使用的方法是否会在方法内部添加任何会导致您所期望的内容变形的内容。 (我想基于特定机器盐你是不知道,如果它这样做或不)
我一直在试图以此来这里http://shagenerator.com/生成一个散列:
ABC|password|1|Test Reference|1.00|20120912123421
给:
25a1804285bafc078f45e41056bcdc42e0508b6f
你能使用我的输入获得与你的代码相同的密钥吗?
更新:
你可以尝试,而不是HashPasswordForStoringInConfigFile()
这种方法,看看你接近:
private string GetSHA1String(string text)
{
var UE = new UnicodeEncoding();
var message = UE.GetBytes(text);
var hashString = new SHA1Managed();
var hex = string.Empty;
var hashValue = hashString.ComputeHash(message);
foreach (byte b in hashValue)
{
hex += String.Format("{0:x2}", b);
}
return hex;
}
更新2:
检查您的编码,我发现我可以匹配散列输出:
var UE = new UTF8Encoding();
更新3:
下面的代码在一个控制台应用程序为我工作,我所看到的哈希生成相同的价值,我能输出比较http://shagenerator.com/也:
using System;
using System.Security.Cryptography;
using System.Text;
using System.Web.Security;
namespace SecurepayPaymentGatewayIntegrationIssue
{
class Program
{
static void Main(string[] args)
{
var text = @"ABC|password|1|Test Reference|1.00|20120912123421";
Console.WriteLine(GetSHA1String(text));
Console.WriteLine(FormsAuthentication.HashPasswordForStoringInConfigFile(text, "sha1").ToLower());
Console.ReadKey();
}
private static string GetSHA1String(string text)
{
var UE = new UTF8Encoding();// ASCIIEncoding(); // UnicodeEncoding();
var message = UE.GetBytes(text);
var hashString = new SHA1Managed();
var hex = string.Empty;
var hashValue = hashString.ComputeHash(message);
foreach (byte b in hashValue)
{
hex += String.Format("{0:x2}", b);
}
return hex;
}
}
}
请您能不能告诉你的代码(带屏蔽的秘密) –
好吧,这是如下:FormsAuthentication.HashPasswordForStoringInConfigFile(“XXX | XXX | 0 | 123 | 100.00 | 20120910203805 “,”sha1“)。ToLower(); –
所以你用这个来创建一个散列密码来保存在配置文件中?只是问,因为文档说它适合存储在配置中。 –