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

Go Language Encryption and Signature Example

Dependencies#

Uses Go standard library only, no external dependencies required.

Full Code#

Usage Instructions#

1.
Signature Generation: Use the GenerateSignature() method, passing HTTP method, path, timestamp, nonce, and raw JSON body
2.
Request Body Encryption: Use the EncryptBody() method, passing raw JSON, App ID, and apiDataKey
3.
Query String Sorting: Use the SortQueryString() method to sort query parameters
4.
Nonce Generation: Use the GenerateNonce() method to generate a random string

Important Notes#

The body used in the signature is always the original JSON string before encryption (even when X-Enc = aes-gcm-v1 is set)
apiDataKey must be a Base64-encoded 32-byte key
Timestamp must be a Unix millisecond timestamp (13 digits)
Content-Type: use application/octet-stream when encrypted, and application/json when plaintext
Go's cipher.NewGCM automatically handles the auth tag; the Seal method returns ciphertext + authTag
Modified at 2026-05-29 12:46:42
Previous
Wallet Query
Next
Python Encryption and Signature Example
Built with