简体   繁体   English

Securepay支付网关集成问题

[英]Securepay payment gateway integration issue

I am working on Securepay Integration with my ASP.NET web page, as per their documentation I am generating SHA1 from following information: 我正在与我的ASP.NET网页进行Securepay集成,根据他们的文档,我正在从以下信息中生成SHA1:

The Fingerprint is a SHA1 hash of the above fields plus the SecurePay Transaction Password in this order with a pipe separator “|”: 指纹是上述字段的SHA1哈希,再加上带有管道分隔符“ |”的SecurePay交易密码,其顺序为:

  1. EPS_MERCHANTID EPS_MERCHANTID
  2. Transaction Password (supplied by SecurePay Support) 交易密码(由SecurePay支持人员提供)
  3. EPS_TXNTYPE (as 0) EPS_TXNTYPE(为0)
  4. EPS_REFERENCEID (for testing purpose 123) EPS_REFERENCEID(用于测试目的123)
  5. EPS_AMOUNT (for testing purpose 100.00) EPS_AMOUNT(用于测试目的100.00)
  6. EPS_TIMESTAMP (for testing purpose 20120910203805) EPS_TIMESTAMP(用于测试目的20120910203805)

Though I have followed above given instruction but whenever I am doing payment it says " Invalid Fingerprint ". 尽管我已经按照上述说明进行操作,但是每当我付款时,它都会显示“ Invalid Fingerprint ”。 Example code: 示例代码:

FormsAuthentication
  .HashPasswordForStoringInConfigFile("xxx|xxx|0|123|100.00|201‌20910203805","sha1")
  .ToLower();`

Check that you are ending the line correctly, either with a trailing '|' 检查您是否正确地结束了行,可以在行尾加上“ |” or removing unnecessary trailing '|'. 或删除不必要的尾随“ |”。

Also check that the method you are using doesn't add anything else inside the method that would distort what you are expecting. 还要检查您使用的方法是否在方法内没有添加任何其他东西,这些东西会扭曲您的期望。 (I am thinking a salt based upon the particular machine you are on don't know if it does this or not) (我在考虑基于您所使用的特定计算机的盐,不知道它是否这样做)

I have been attempting to generate a hash here http://shagenerator.com/ using this: 我一直在尝试使用以下方法在此处http://shagenerator.com/生成哈希:

ABC|password|1|Te‌​st Reference|1.00|20120912123421

gives: 得到:

25a1804285bafc078f45e41056bcdc42e0508b6f

Can you get the same key with your code using my input? 您可以使用我的输入获得与您的代码相同的密钥吗?

Update: 更新:

Can you try this method instead of HashPasswordForStoringInConfigFile() and see if you get closer: 您可以尝试使用此方法代替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;
}

UPDATE 2: 更新2:

Check your encoding, I discovered that I can match the hash output with: 检查您的编码,我发现我可以将哈希输出与:

var UE = new UTF8Encoding();

UPDATE 3: 更新3:

The following code worked for me in a console app, I was seeing the hashes generate the same value and I was able to compare the output to http://shagenerator.com/ also: 以下代码在控制台应用程序中为我工作,我看到哈希值生成相同的值,并且还可以将输出与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|Te‌​st 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;
        }
    }
}

I had same problem and i solved this using below method: 我有同样的问题,我使用以下方法解决了这个问题:

 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();
        }

In page load I Converted this return value into lower case. 在页面加载中,我将此返回值转换为小写。 because the above method return value with upper case 因为上述方法使用大写字母返回值

string VAL="ABC|password|1|Te‌​st Reference|1.00|20120912123421";
fingerPrint = GetSHA1HashData(VAL);

use the time as UTC Now: string epsTimestamp = DateTime.UtcNow.ToString(@"yyyyMMddHHmmss"); 将时间用作现在的UTC: string epsTimestamp = DateTime.UtcNow.ToString(@"yyyyMMddHHmmss");

And also make sure you have used sha1 for encryption: 并确保已使用sha1进行加密:

string data = EpsMerchant + "|" + EpsPassword + "|" + EpsTxnType + "|" + 
EpsReferenceId + "|" + EpsAmount + "|" + epsTimestamp;
string epsFingerprint = GetSha1String(data);

And below is the code for getting sha1 下面是获取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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM