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

Python Encryption and Signature Example

Dependencies#

Full Code#

Usage Instructions#

1.
Signature Generation: Use the generate_signature() method and pass the HTTP method, path, timestamp, nonce, and original JSON body
2.
Request Body Encryption: Use the encrypt_body() method and pass the original JSON, App ID, and apiDataKey
3.
Query String Sorting: Use the sort_query_string() method to sort query parameters

Notes#

The body used in the signature always uses the original JSON string before encryption (even when X-Enc = aes-gcm-v1 is set)
apiDataKey must be a Base64-encoded 32-byte key
The timestamp uses a Unix millisecond timestamp (13-digit number)
Content-Type: use application/octet-stream when encrypted, and application/json when plaintext
Modified at 2026-05-29 13:03:56
Previous
Go Language Encryption and Signature Example
Next
PHP encryption and signature example
Built with