Signing requests
Every request is signed with your RSA private key. Every response and webhook is signed with AegisPay's. There are no shared secrets or bearer tokens.
Algorithm #
| Parameter | Value |
|---|---|
| Signature scheme | RSASSA-PSS (RFC 8017) |
| Hash / MGF | SHA-256 / MGF1 with SHA-256 |
| Salt length | 32 bytes exactly (other lengths are rejected) |
| Key size | RSA 2048, 3072 (recommended) or 4096 bits, exponent 65537 |
| Encoding | Standard Base64 with padding, no line breaks; text is UTF-8 |
PKCS#1 v1.5 signatures (PHP's openssl_sign default) are rejected.
Request headers #
| Parameter | Type | Required | Description |
|---|---|---|---|
| X-Aegis-Merchant-Id | string | Yes | Your merchant ID, mch_ + 16–32 letters/digits. |
| X-Aegis-Key-Id | string | Yes | The key you signed with, key_… from the dashboard. |
| X-Aegis-Timestamp | string | Yes | Unix seconds (10 digits). Must be within ±300 s of AegisPay's clock: run NTP. |
| X-Aegis-Nonce | string | Yes | Unique per request, 22–64 chars of A-Z a-z 0-9 _ -. Use 16+ random bytes, base64url. |
| Idempotency-Key | string | Conditional | Required on every POST. 8–64 chars of A-Z a-z 0-9 _ -. See idempotency. |
| X-Aegis-Signature | string | Yes | Base64 signature of the canonical string. |
| Content-Type | string | Conditional | application/json when there is a body. Not signed. |
Each header must appear exactly once. Duplicates are rejected.
The canonical string #
Eleven fields joined by a single line feed (\n). No trailing line feed, no carriage returns.
AEGIS1-REQUEST-RSA-PSS-SHA256 (1) fixed label
<METHOD> (2) upper-case: GET, POST
<host> (3) API host, lower-case, no scheme, no port
<path> (4) path exactly as sent, e.g. /v1/payments/pay_123
<canonical_query> (5) see below; empty line if no query
<merchant_id> (6) = X-Aegis-Merchant-Id
<key_id> (7) = X-Aegis-Key-Id
<timestamp> (8) = X-Aegis-Timestamp
<nonce> (9) = X-Aegis-Nonce
<idempotency_key> (10) = Idempotency-Key, or empty line if not sent
<body_sha256> (11) lower-case hex SHA-256 of the raw body bytes- Host: the API host you call, e.g.
sandbox-api.aegispay8.com. Because it's signed, a sandbox request can never be replayed against production. - Path: exactly as on the request line, before
?. Don't decode it, don't add or remove a trailing slash. - Body: hash the exact bytes you send. Serialise your JSON once, hash that string, send that string. An empty body hashes to
e3b0c442…b855.
Canonical query
- Take the raw query string without
?. Empty query → empty line. - Split on
&, then each pair on the first=. Decode as form data (+is a space,%XXis UTF-8). - Re-encode per RFC 3986: everything except
A–Z a–z 0–9 - . _ ~becomes%XXwith upper-case hex. - Sort by name, then value (byte order), and join as
name=valuewith&.
| Raw query | Canonical query |
|---|---|
| status=paid&limit=20 | limit=20&status=paid |
| b=2&a=1&a=0 | a=0&a=1&b=2 |
| q=hello+world&x=%7e&y=a%2Fb | q=hello%20world&x=~&y=a%2Fb |
| flag | flag= |
Sign it
signature = Base64( RSASSA-PSS-SIGN( private_key, SHA-256, MGF1-SHA-256, salt = 32, UTF-8(canonical_string) ) )With OpenSSL (useful for testing):
printf '%s' "$CANONICAL" | openssl dgst -sha256 \
-sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:32 -sigopt rsa_mgf1_md:sha256 \
-sign aegispay_private.pem | base64 | tr -d '\n'Worked example #
This uses the public test key from the test vectors.
POST /v1/payments HTTP/1.1
Host: api.aegispay8.com
Content-Type: application/json
X-Aegis-Merchant-Id: mch_TEST0000000000000001
X-Aegis-Key-Id: key_TEST0000000000000001
X-Aegis-Timestamp: 1795400000
X-Aegis-Nonce: n0nce_create_00000000000001
Idempotency-Key: idem_ORDER-1001_attempt1
X-Aegis-Signature: <Base64 signature>
{"amount":"150.00","currency":"MYR","method":"fpx","merchant_reference":"ORDER-1001","description":"Order #1001","customer":{"name":"Siti Aminah","email":"siti@example.com"},"return_url":"https://shop.example.com/return","callback_url":"https://shop.example.com/aegis/webhook"}Canonical string (line 5 is empty because there is no query):
AEGIS1-REQUEST-RSA-PSS-SHA256
POST
api.aegispay8.com
/v1/payments
mch_TEST0000000000000001
key_TEST0000000000000001
1795400000
n0nce_create_00000000000001
idem_ORDER-1001_attempt1
bb614f65ef869b8465e351d23b93d577e75a824ea71e7db02255cfa0b8ab49a7Its SHA-256 is d05bc2228c6ba68ec5e3baea0c7cfa256e218d3ba21180ff491f3ed5f1dc4999. If yours matches, your code is correct up to the signing step.
Verify every response #
Every response, including errors, has X-Aegis-Key-Id, X-Aegis-Timestamp, X-Aegis-Nonce and X-Aegis-Signature. The signature covers:
AEGIS1-RESPONSE-RSA-PSS-SHA256
<HTTP status code, e.g. 201>
<request METHOD>
<request path>
<your merchant_id> (empty if your request had no valid merchant id)
<YOUR request nonce> (empty if your request had no valid nonce)
<X-Aegis-Key-Id>
<X-Aegis-Timestamp>
<X-Aegis-Nonce>
<lower-case hex SHA-256 of the raw response body>Your own request nonce is inside the signature, so a response is only valid for the request you just sent. Reject the response (treat the outcome as unknown, then retry with the same Idempotency-Key or re-query) if:
- the signature is invalid;
- the key ID is not one of your pinned AegisPay keys;
- the timestamp is more than 300 s from your clock.
Your keys #
Rotation (no downtime)
- Register a new key in the dashboard (API keys). You can have two active keys at once.
- Deploy your servers with the new private key and its key ID.
- Revoke the old key. Revoking takes effect within 30 seconds and cannot be undone.
Rotate at least every 12 months, and immediately if someone with access leaves. If a private key may have leaked, revoke it first and investigate second.
AegisPay's keys
Get them from GET /v1/platform-keys and pin them in your config. When AegisPay rotates, the new key is published at least 30 days before it's used. Never accept a key just because a response or webhook names it.
Debugging AUTH_FAILED #
AUTH_FAILED deliberately doesn't say which check failed, so attackers learn nothing. If you're stuck, send AegisPay support the request_id from the error body and we can tell you the exact reason. Most common causes:
- The body was re-serialised after signing (different spacing or key order).
- Wrong host in line 3: it must be the host you call, e.g.
sandbox-api.aegispay8.com. - A trailing newline at the end of the canonical string.
- PKCS#1 v1.5 instead of PSS, or a salt length other than 32.
- The key isn't active yet (finish the challenge step), or you used the sandbox key against production.
Verify a signature yourself:
# canonical.txt must have NO trailing newline
base64 -d <<< "$SIGNATURE" > sig.bin
openssl dgst -sha256 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:32 -sigopt rsa_mgf1_md:sha256 \
-verify aegispay_public.pem -signature sig.bin canonical.txtTest vectors #
Download aegis1-vectors.json. It has query examples, three valid requests with their exact canonical strings, negative cases with their expected errors, a signed response, a signed webhook, and a key registration. Its keys are public test keys: never use them for anything else.
RSA-PSS is randomised, so your signatures never byte-match the vectors. Instead: (1) compare your canonical strings byte-for-byte, (2) verify the vectors' signatures with the test public key, and (3) sign with the test private key and verify your own signature. Use each vector's verify_at_unix as "now".