[英]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.