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
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"
}
Obtain the value of the
rsa-signature
header (if callback) OR the value of thersa_signature
query parameter (if redirect).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_reference
and these values are obtained from the callback/redirect data. The string payload would therefore be266:GOVNETJFTKL9BSYQQKVKRU:COMPLETED:CSTREF2NZQQW53KJMQPE
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