1. Examples of encryption and signature
English
  • Chinese
  • English
  • Open API Documentation
  • Payin
    • Payin Order - General
    • Payin Order - India
    • Payin Order - Philippines
    • Payin Order - Indonesia
    • Payin Order - Vietnam
    • Payin Order - Cryptocurrency
    • Payin Order - China
    • Payin Order - Malaysia
    • Payin Order - Pakistan
    • Payin Order - Thailand
  • Payout
    • Payout Order - General
    • Payout Order - India
    • Payout Order - Philippines
    • Payout Order - Indonesia
    • Payout Order - Vietnam
    • Payout Order - Cryptocurrency
    • Payout Order - Malaysia
    • Payout Order - Pakistan
    • Payout Order - Thailand
  • Callback Notification
    • Callback Description
    • Collection Callback
    • Payout Callback
  • Query API
    • Collection Order Query
    • Payout Order Query
    • Wallet Query
  • Examples of encryption and signature
    • Go Language Encryption and Signature Example
    • Python Encryption and Signature Example
    • PHP encryption and signature example
    • Node.js encryption and signature example
    • Environment variables and request body JSON example
    • Java encryption and signature example
  • Other instructions
    • Response Status Description
    • Order Status Description
    • Payment Method List
    • Bank Code List
    • Checkout iframe Copy Function Support Description
    • Backend Login Instructions
  1. Examples of encryption and signature

PHP encryption and signature example

Dependencies#

Uses the PHP standard library (OpenSSL) with no additional dependencies required.
Requires PHP >= 7.1 (supports GCM mode).

Full Code#

Usage Instructions#

1.
Generate Signature: Use the static generateSignature() method and pass in the HTTP method, request path, timestamp, nonce, and the original JSON body.
2.
Encrypt Request Body: Use the static encryptBody() method and pass in the original JSON, App ID, and apiDataKey.
3.
Sort Query String: Use the static sortQueryString() method to sort query parameters.
4.
Generate Nonce: Use the static generateNonce() method to generate a random string.

Notes#

The body used in the signature must always be the original JSON string before encryption (even when X-Enc = aes-gcm-v1 is enabled).
apiDataKey must be a Base64-encoded 32-byte key.
The timestamp must use a Unix timestamp in milliseconds (13 digits).
Content-Type: use application/octet-stream for encrypted payloads and application/json for plaintext payloads.
In GCM mode, PHP’s openssl_encrypt() fills the $tag parameter with a 16-byte authentication tag (authTag).
The AAD (Additional Authenticated Data) parameter in GCM mode is only supported in PHP 7.1+.

PHP Version Requirements#

PHP >= 7.1 (supports the AAD parameter in GCM mode)
Modified at 2026-05-29 13:09:12
Previous
Python Encryption and Signature Example
Next
Node.js encryption and signature example
Built with