Authentication and Security
This page provides a comprehensive reference for GatePay API authentication, security protocols, and signature generation.Protocol Requirements
All GatePay API requests must adhere to the following specifications:| Aspect | Requirement |
|---|---|
| Transport | HTTPS, TLS 1.2 or higher |
| Data Format | JSON (Content-Type: application/json) |
| Signature Algorithm | HMAC-SHA512 |
Unified Response Structure
All API responses follow a consistent format with the following fields:| Field | Type | Description |
|---|---|---|
status | string | API result: SUCCESS or FAIL |
code | string | Error code (null on success) |
label | string | Error name (null on success) |
errorMessage | string | Error description (null on success) |
data | object/array/string/null | Business data payload |
Request Headers
All API requests must include the following headers:| Header | Description | Example |
|---|---|---|
X-GatePay-Certificate-ClientId | ClientId assigned after app creation. Uniquely identifies your application. | app_abc123def456 |
X-GatePay-On-Behalf-Of | (Optional) Institution sub-account ID. Include only when making requests on behalf of a sub-account. | sub_account_123 |
X-GatePay-Timestamp | UTC timestamp in milliseconds. Requests with timestamp drift greater than 10 seconds are rejected. | 1704067200000 |
X-GatePay-Nonce | Random string for replay prevention. Recommended length ≤ 32 characters; alphanumeric only (letters and digits). | abc123xyz789 |
X-GatePay-Signature | Request signature computed using HMAC-SHA512. See signature generation below. | <64-char-hex-string> |
Signature Generation
The signature ensures request integrity and authenticity. Follow these steps to generate a valid signature:Signature String Format
The signature string consists of three lines, each ending with a newline character (\n):
- Line 1: X-GatePay-Timestamp value
- Line 2: X-GatePay-Nonce value
- Line 3: Raw JSON request body (empty string if no request body)
- Trailing newline: Always include a final newline after line 3
Signature Generation Steps
-
Generate Headers: Create
X-GatePay-Timestamp(current UTC time in milliseconds) andX-GatePay-Nonce(random string, ≤ 32 alphanumeric characters). - Prepare Request Body: Extract the raw JSON request body as a string. If there is no request body (e.g., GET requests), use an empty string.
-
Build Signature String: Concatenate the timestamp, nonce, and body with newlines:
- Compute HMAC-SHA512: Use your Payment API Secret as the key to compute the HMAC-SHA512 hash of the signature string. Output the result as a hexadecimal string.
-
Set Header: Set the computed hash as the
X-GatePay-Signaturerequest header.
Example: Signature Generation (POST Request)
Request Details:- Timestamp:
1704067200000 - Nonce:
abc123xyz789 - Payment API Secret:
my_secret_key - Request body:
{"merchantTradeNo": "order_123", "currency": "USDT", "orderAmount": "100"}
Example: Signature Generation (GET Request)
For GET requests with no body: Request Details:- Timestamp:
1704067200000 - Nonce:
xyz789abc123 - Payment API Secret:
my_secret_key - Request body: (empty)
Callback Verification
When GatePay sends callbacks to your webhook endpoint, verify the callback signature using the same method:Callback Headers
Callbacks include the following headers for signature verification:| Header | Description |
|---|---|
X-GatePay-Timestamp | UTC timestamp when the callback was sent |
X-GatePay-Nonce | Random string used during signature generation |
X-GatePay-Signature | Callback signature |
Callback Verification Steps
-
Extract the callback headers:
X-GatePay-Timestamp,X-GatePay-Nonce, andX-GatePay-Signature. - Read the raw callback body (JSON).
-
Build the signature string:
- Compute HMAC-SHA512 using your Payment API Secret as the key.
-
Compare the computed signature with the
X-GatePay-Signatureheader. If they match, the callback is authentic. - Additionally, verify that the timestamp is within an acceptable range (e.g., within the last 5 minutes) to prevent replay attacks.
Signature Verification Tool
For testing and debugging signature verification, use the GatePay Signature Utility: GatePay Signature Verification Tool This tool allows you to:- Generate test signatures
- Verify signature correctness
- Debug signature mismatches
Best Practices
- Timestamp Validation: Always validate that the request timestamp is within 10 seconds of your server’s current UTC time.
- Nonce Uniqueness: Use a unique nonce for each request to prevent replay attacks. Consider storing used nonces in a cache with a short TTL (e.g., 15 minutes).
- Secret Management: Store your Payment API Secret and Authorization Secret securely. Never hardcode secrets in your source code or commit them to version control.
- HTTPS Only: All requests must use HTTPS with TLS 1.2 or higher. Reject any non-HTTPS requests.
- Callback Security: Always verify callback signatures before processing. Implement idempotency checks on your callback endpoint to handle duplicate deliveries.
- Error Handling: For signature errors, respond with HTTP 400 (Bad Request) and log the mismatch for investigation.
Related Guides
- Merchant Access Guide — Retrieve and manage your credentials.
- Payments Guide — Integrate payment processing.
- Notification Callbacks Guide — Handle asynchronous payment callbacks.
- Error Codes and Best Practices — Troubleshoot authentication errors.

