简体   繁体   English

使用SHA256的PayFort签名

[英]PayFort Signature using SHA256

https://docs.payfort.com/docs/in-common/build/index.html#create-signature-value https://docs.payfort.com/docs/in-common/build/index.html#create-signature-value

I need some assistance regarding generating SHA256 Signature for PayFort Tokenization. 我需要一些有关生成PayFort令牌化SHA256签名的帮助。 The example in the link gives you basic guideline on how to tokenize your request, but what I need is information on how to generate SHA256 Signature with a secret key and decrypt the response signature with a key. 链接中的示例为您提供了有关如何标记请求的基本指南,但我需要的是有关如何使用密钥生成SHA256签名以及如何使用密钥解密响应签名的信息。 I have all the data required for request and response paraphrase keys. 我拥有请求和响应短语密钥所需的所有数据。 I don't exactly understand how to generate proper SHA256 Signature with a secret key in C#. 我不完全了解如何使用C#中的密钥生成正确的SHA256签名。 I tried different examples to generate SHA256 signature, but it returns signature mismatch. 我尝试了其他示例来生成SHA256签名,但它返回的签名不匹配。

The example from PayFort's Documentation: PayFort文档中的示例:

SHA Request Phrase: PASS 
SHA-Type: SHA-256

PASSaccess_code=SILgpo7pWbmzuURp2qrilanguage=enmerchant_identifier=MxvOupuGmerchant_reference=MyReference0001service_command=TOKENIZATIONPASS

How can I properly encrypt and decrypt it in C#. 如何在C#中正确加密和解​​密它。

Any help is appreciated. 任何帮助表示赞赏。

Edit: 编辑:

I am firing in the blind, Anybody familiar with PayFort Integration with C# can guide me 我在盲目射击,熟悉C#的PayFort集成的任何人都可以指导我

public static String Sign(String data, String key)
{
    KeyedHashAlgorithm algorithm = new HMACSHA256();
    Encoding encoding = new UTF8Encoding();
    algorithm.Key = encoding.GetBytes(key);
    return Convert.ToBase64String(algorithm.ComputeHash(
        encoding.GetBytes(data.ToCharArray())));
}

Firstly you need to generate your signature as a string. 首先,您需要将您的签名生成为字符串。 Signature includes accesscode, language etc. Then convert that signature to bytes. 签名包括访问码,语言等。然后将该签名转换为字节。 Then initialize a sha256Managed object. 然后初始化一个sha256Managed对象。 Pass the bytes paramter to that object and this will return you another byte but with sha256Managed format. 将字节参数传递给该对象,这将返回另一个字节,但具有sha256Managed格式。 Now you need to set its format in foreach. 现在,您需要在foreach中设置其格式。

Please find the below code this will help you out. 请找到以下代码,这将对您有所帮助。

byte[] bytes = Encoding.UTF8.GetBytes(signature);
            SHA256Managed hashstring = new SHA256Managed();
            byte[] hash = hashstring.ComputeHash(bytes);
            string hashString = string.Empty;
            foreach (byte x in hash)
            {
                hashString += String.Format("{0:x2}", x);
            }

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

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