Signing issue when sending payload to Swish API

183 Views Asked by At

I am trying to send a payload to Swish (Swedish payment system), using TLS- and signing certificates. I am currently working with the Merchant Swish Simulator and using test-certificates from Swish documentation.

When sending the payload and signature (to endpont /api/v1/payouts) I get this error:

{StatusCode: 401, ReasonPhrase: 'Unauthorized', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Date: Tue, 12 Apr 2022 07:02:19 GMT
  Server: openresty/1.15.8.3
  Vary: Origin
  Vary: Access-Control-Request-Method
  Vary: Access-Control-Request-Headers
  Transfer-Encoding: chunked
  Content-Type: application/json
}}

The code below is used to generate the signature

var payloadJson = JsonConvert.SerializeObject(payload, Formatting.None, serializerSettings);
var payloadJsonBuffer = Encoding.UTF8.GetBytes(payloadJson);
using var sha512 = SHA512.Create();
var hashedBuffer = sha512.ComputeHash(payloadJsonBuffer);
using var rsa = signCert.GetRSAPrivateKey();
var signedBuffer = rsa.SignHash(hashedBuffer, HashAlgorithmName.SHA512, RSASignaturePadding.Pkcs1);
var signature = Convert.ToBase64String(signedBuffer, Base64FormattingOptions.None);
var requestBody = new SwishPayoutRequestBody
{
    Payload = payload,
    Signature = signature
};

Does anyone have an idea to how to approach this issue or have any experience with working with Swish API using c#?

Thanks!

0

There are 0 best solutions below