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