简体   繁体   English

如何使用SHA-512让Ogone支持字段值中的特殊字符

[英]How to get Ogone to support special characters in field values with SHA-512

We implemented SHA-512 hashing for the Ogone payment platform. 我们为Ogone付款平台实施了SHA-512哈希。 This means we have to hash all values of all the FORM variables. 这意味着我们必须对所有FORM变量的所有值进行哈希处理。

However, whenever a field has special characters the Hash is not accepted by Ogone. 但是,只要字段具有特殊字符,Ogone都不接受哈希。 The payment page will than be rendered with the documented error: error order/1/s 付款页面将显示为已记录的错误: error order / 1 / s

Ogone has a test-page available to test a string and get SHA512: https://secure.ogone.com/ncol/test/testsha_UTF8.asp Ogone有一个测试页面可用于测试字符串并获取SHA512: https ://secure.ogone.com/ncol/test/testsha_UTF8.asp

Here are the examples that I used for unit testing. 这是我用于单元测试的示例。

[TestMethod]
public void EncodePaiosBajos_ResultsInExpectedSha512String()
{
  string name = "Paios Bajos";
  string result = PaymentProviderHelper.ShaEncode(name, new SHA512Managed());
  string expected = "3AC80D8A5B1AF7DF3530027269B807B097B6C770F168509ED7A8148E941AEA3369112F1B5BF1BE0965D0FE9AB83C1AB1CB7BF22DFD733E120A6A828600EFE643";
  Assert.AreEqual(expected, result);
}

[TestMethod]
public void EncodePaiosBajosSpecialCharacters_ResultsInExpectedSha512String()
{
  string name = "Países Bajos";
  string result = PaymentProviderHelper.ShaEncode(name, new SHA512Managed());
  string expected = "D4F8FFEC3FA0A3146C9611294569FF861CFF0E8C26982DA8D492DAB5D67B380558BFA0571A7D0DF49407B5075AE4DCE76253603075AF9350EA180ED32FA96026";
  Assert.AreEqual(expected, result);
}

The PaymentProviderHelper.ShaEncode method looks like this: PaymentProviderHelper.ShaEncode方法如下所示:

 internal static string ShaEncode(string signature, HashAlgorithm shaEncoding)
        {
            shaEncoding.Initialize();
            // Encode signature
            byte[] buffer = Encoding.ASCII.GetBytes(signature);
            shaEncoding.ComputeHash(buffer);

            // Return the encoded string in hexidecimal
            String returnValue = String.Empty;
            foreach (byte c in shaEncoding.Hash)
            {
                returnValue += String.Format("{0:X2}", (int)c);
            }

            return returnValue;
        }

Question: Why does the second unit test fail? 问题:第二个单元测试为什么失败?

Is there something wrong in this Encode implementation for special characters perhaps? 此特殊字符的Encode实现中可能有问题吗?

Tests are in C#.NET 4.5 测试在C#.NET 4.5中

The ogone's test page uses UTF8 encoding (basing on URL) to product hashes. ogone的测试页将UTF8编码(基于URL)用于产品哈希。 Yet in your implementation you use Encoding.ASCII . 然而,在您的实现中,您使用Encoding.ASCII Simply change your implementation encoding to Encoding.UTF8 . 只需将实现编码更改为Encoding.UTF8

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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