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.

The ready-made clients in Code libraries do all of this for you and are tested against the test vectors. Read on if you're writing your own, or debugging.

Algorithm #

ParameterValue
Signature schemeRSASSA-PSS (RFC 8017)
Hash / MGFSHA-256 / MGF1 with SHA-256
Salt length32 bytes exactly (other lengths are rejected)
Key sizeRSA 2048, 3072 (recommended) or 4096 bits, exponent 65537
EncodingStandard Base64 with padding, no line breaks; text is UTF-8

PKCS#1 v1.5 signatures (PHP's openssl_sign default) are rejected.

Request headers #

ParameterTypeRequiredDescription
X-Aegis-Merchant-IdstringYesYour merchant ID, mch_ + 16–32 letters/digits.
X-Aegis-Key-IdstringYesThe key you signed with, key_… from the dashboard.
X-Aegis-TimestampstringYesUnix seconds (10 digits). Must be within ±300 s of AegisPay's clock: run NTP.
X-Aegis-NoncestringYesUnique per request, 22–64 chars of A-Z a-z 0-9 _ -. Use 16+ random bytes, base64url.
Idempotency-KeystringConditionalRequired on every POST. 8–64 chars of A-Z a-z 0-9 _ -. See idempotency.
X-Aegis-SignaturestringYesBase64 signature of the canonical string.
Content-TypestringConditionalapplication/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.

text
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

  1. Take the raw query string without ?. Empty query → empty line.
  2. Split on &, then each pair on the first =. Decode as form data (+ is a space, %XX is UTF-8).
  3. Re-encode per RFC 3986: everything except A–Z a–z 0–9 - . _ ~ becomes %XX with upper-case hex.
  4. Sort by name, then value (byte order), and join as name=value with &.
Raw queryCanonical query
status=paid&limit=20limit=20&status=paid
b=2&a=1&a=0a=0&a=1&b=2
q=hello+world&x=%7e&y=a%2Fbq=hello%20world&x=~&y=a%2Fb
flagflag=

Sign it

text
signature = Base64( RSASSA-PSS-SIGN( private_key, SHA-256, MGF1-SHA-256, salt = 32, UTF-8(canonical_string) ) )

With OpenSSL (useful for testing):

bash
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.

http
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):

text
AEGIS1-REQUEST-RSA-PSS-SHA256
POST
api.aegispay8.com
/v1/payments

mch_TEST0000000000000001
key_TEST0000000000000001
1795400000
n0nce_create_00000000000001
idem_ORDER-1001_attempt1
bb614f65ef869b8465e351d23b93d577e75a824ea71e7db02255cfa0b8ab49a7

Its 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:

text
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)

  1. Register a new key in the dashboard (API keys). You can have two active keys at once.
  2. Deploy your servers with the new private key and its key ID.
  3. 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:

bash
# 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.txt

Test 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".