[英]Securepay payment gateway integration issue
我正在与我的ASP.NET网页进行Securepay集成,根据他们的文档,我正在从以下信息中生成SHA1:
指纹是上述字段的SHA1哈希,再加上带有管道分隔符“ |”的SecurePay交易密码,其顺序为:
尽管我已经按照上述说明进行操作,但是每当我付款时,它都会显示“ Invalid Fingerprint ”。 示例代码:
FormsAuthentication
.HashPasswordForStoringInConfigFile("xxx|xxx|0|123|100.00|20120910203805","sha1")
.ToLower();`
检查您是否正确地结束了行,可以在行尾加上“ |” 或删除不必要的尾随“ |”。
还要检查您使用的方法是否在方法内没有添加任何其他东西,这些东西会扭曲您的期望。 (我在考虑基于您所使用的特定计算机的盐,不知道它是否这样做)
我一直在尝试使用以下方法在此处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;
}
}
}
我有同样的问题,我使用以下方法解决了这个问题:
private string GetSHA1HashData(string data)
{
SHA1 sha1 = new SHA1CryptoServiceProvider();
//convert the input text to array of bytes
byte[] hashData = sha1.ComputeHash(Encoding.Default.GetBytes(data));
//create new instance of StringBuilder to save hashed data
StringBuilder returnValue = new StringBuilder();
//loop for each byte and add it to StringBuilder
for (int i = 0; i < hashData.Length; i++)
{
returnValue.Append(hashData[i].ToString("x2"));
}
// return hexadecimal string
return returnValue.ToString();
}
在页面加载中,我将此返回值转换为小写。 因为上述方法使用大写字母返回值
string VAL="ABC|password|1|Test Reference|1.00|20120912123421";
fingerPrint = GetSHA1HashData(VAL);
将时间用作现在的UTC: string epsTimestamp = DateTime.UtcNow.ToString(@"yyyyMMddHHmmss");
并确保已使用sha1进行加密:
string data = EpsMerchant + "|" + EpsPassword + "|" + EpsTxnType + "|" +
EpsReferenceId + "|" + EpsAmount + "|" + epsTimestamp;
string epsFingerprint = GetSha1String(data);
下面是获取sha1的代码
string GetSha1String(string input)
{
StringBuilder stringBuilder = new StringBuilder();
foreach (byte b in GetHash(input))
stringBuilder.Append(b.ToString("X2"));
return stringBuilder.ToString();
}
public static byte[] GetHash(string inputString)
{
HashAlgorithm obj = SHA1.Create();
return obj.ComputeHash(Encoding.UTF8.GetBytes(inputString));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.