RSA Signature Verification

The section describes how the RSA signature sent in the callback header or redirect query data can be verified. For verification to succeed, the public key is required.

Download the Public Key File

Download the public key file by clicking the link below and store it somewhere on your server

Public key for sandbox webhook signature verification
Public key for production webhook signature verification

Next Steps

Below is the sample callback data for this demonstration (sample redirect data is available here);

{
  "id": 266,
  "merchant_reference": "CSTREF2NZQQW53KJMQPE",
  "internal_reference": "GOVNETJFTKL9BSYQQKVKRU",
  "transaction_type": "COLLECTION",
  "request_currency": "UGX",
  "request_amount": 23000,
  "transaction_currency": "UGX",
  "transaction_amount": 23000,
  "transaction_fee": 690,
  "charge_customer": false,
  "total_credit": 22310,
  "provider_code": "airtel_money_ug",
  "transaction_status": "COMPLETED",
  "status_message": "Transaction Completed Successfully",
  "transaction_account": "256752000001",
  "customer_name": "SANDBOX CUSTOMER",
  "institution_name": "Airtel Money"
}
  1. Obtain the value of the rsa-signature header (if callback) OR the value of the rsa_signature query parameter (if redirect).

  2. Form the string payload to be used in signature verification. This is obtained by concatenating values of the callback/redirect data in the format; id:internal_reference:transaction_status:merchant_referenceand these values are obtained from the callback/redirect data. The string payload would therefore be 266:GOVNETJFTKL9BSYQQKVKRU:COMPLETED:CSTREF2NZQQW53KJMQPE

  3. Use the public key obtained above to verify the signature as described in the sample source codes below;

<?php

public function isValidSignature() {
    $file = "path-to-file/govnet.public.key.pem";
    $keyContent = file_get_contents($file);
    $publicKey = openssl_get_publickey($keyContent);
    $strPayload = "266:GOVNETJFTKL9BSYQQKVKRU:COMPLETED:CSTREF2NZQQW53KJMQPE";
    $signature = base64_decode("value-of-rsa-signature");

    /*true or false*/
    return openssl_verify($strPayload, $signature, $publicKey, "sha256") == 1;
}

?>

Last updated