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