Skip to main content

7. Signature Generation (Request)

SADAD requires merchants to generate a SHA256 signature to ensure the authenticity and integrity of each payment request.

The signature must be generated server-side using your Secret Key and sent along with the transaction request.


Exact Steps

  1. Collect all mandatory parameters except signature
  2. Sort parameters alphabetically by key name
  3. Prefix the string with your Secret Key
  4. Concatenate only the parameter values (no keys, no separators)
  5. Generate a SHA256 hash
  6. Convert the hash output to uppercase

Code Samples (Primary Languages)

<?php
$secretKey = "YOUR_TEST_SECRET_KEY";
$params = [
"CALLBACK_URL"=>"https://yoursite.com/callback",
"MOBILE_NO"=>"97412345678",
"ORDER_ID"=>"ORD-20251216-001",
"TXN_AMOUNT"=>"150.00",
"WEBSITE"=>"MYSHOP",
"email"=>"[email protected]",
"merchant_id"=>"123456",
"txnDate"=>"2025-12-16"
];
ksort($params);
$string=$secretKey;
foreach($params as $v){$string.=$v;}
echo strtoupper(hash('sha256',$string));
?>

Additional Language Examples

Ruby / Rails
require 'digest'
secret="YOUR_TEST_SECRET_KEY"
params={
"CALLBACK_URL"=>"https://yoursite.com/callback",
"MOBILE_NO"=>"97412345678",
"ORDER_ID"=>"ORD-20251216-001",
"TXN_AMOUNT"=>"150.00",
"WEBSITE"=>"MYSHOP",
"email"=>"[email protected]",
"merchant_id"=>"123456",
"txnDate"=>"2025-12-16"
}
puts Digest::SHA256.hexdigest(secret + params.sort.to_h.values.join).upcase
Go
import (
"crypto/sha256"
"fmt"
"sort"
)
s := secret + sortedValues
fmt.Printf("%X", sha256.Sum256([]byte(s)))
Kotlin
val s = secret + params.values.joinToString("")
val hash = MessageDigest.getInstance("SHA-256").digest(s.toByteArray())
println(hash.joinToString("") { "%02X".format(it) })
Swift
let s = secret + params.sorted{$0.key<$1.key}.map{$0.value}.joined()
print(SHA256.hash(data: s.data(using:.utf8)!))
PowerShell
$hash = [System.Security.Cryptography.SHA256]::Create()
C / C++ / Objective-C / R / Clojure / OCaml

Use the platform cryptographic library to generate:

SHA256(secret_key + concatenated_sorted_parameter_values)

Important Notes

caution
  • Do not URL-encode values before signature generation
  • Do not include the signature parameter in the hash
  • Parameter order must be alphabetical by key
  • Signature generation must always be done server-side