Formatowanie wiadomości pod HMAC SHA256

0

Cześć,
pomocy, bo już mi się pomysły skończyły..
Chcę użyć api, wiadomość musi być zaszyfrowana poniższą metodą. Wg dokumentacji dla wiadomości:

{
    "amount": 45671,
    "externalId": "234567898654",
    "description": "Test transaction",
    "buyer": {
        "email": "[email protected]"
    }
}

oraz klucza:

Signature-Key = s3ecret-k3y

powinienem otrzymać wynik

aYPCytCoc+/wFgqHZJjgBCi20omXTn0yzm9LysJgnFo=

Próbowałem chyba na wszystkie możliwe sposoby formatować wiadomość, ale nigdy nie dostaję tego samego wyniku. Próbowałem również serializacji.
W dokumentacji znajduje się uwaga:

NOTE: If you are trying to calculate the signature from the example in your code and are getting a different result, make sure that your JSON message is formatted the same way as the message in the example, i.e. with four-space indentation and no newline character at the end.

using System;
using System.Security.Cryptography;

public class HashCalculator {

    public static void Main() {
        String dataToHash = "sample_request_content";
        String key = "s3ecret-k3y";
        var encoder = new System.Text.UTF8Encoding();

        String hmacHash = calculateHMAC(encoder.GetBytes(dataToHash), encoder.GetBytes(key));
        Console.WriteLine(hmacHash);
    }

    private static string calculateHMAC(byte[] data, byte[] key) {
        var hmacsha256 = new HMACSHA256(key);
        byte[] hashmessage = hmacsha256.ComputeHash(data);
        return Convert.ToBase64String(hashmessage);
    }
}

Pozdrawiam

1

OK Google Fu: https://docs.paynow.pl/#section/Payments/Make-a-payment

NOTE: If you are trying to calculate the signature from the example in your code and are getting a different result, make sure that your JSON message is formatted the same way as the message in the example, i.e. with four-space indentation and no newline character at the end.

Może o to chodzi???

PS. Jest też przykład w PHP: https://github.com/pay-now/paynow-php-sdk/blob/master/src/Paynow/Util/SignatureCalculator.php

0

Dzięki!

dataToHash.Replace("\r\n", "\n");

Załatwiło sprawę. Wydaje mi się, że tego wczoraj próbowałem, ale może mi się wydawać :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1