Session Key Decryption Guide
After a user completes login within the game, SUD OP SVR generates a session key (sessionKey) for the current user's login state, encrypts it into encrypted_session_key, and delivers it to the APP Server (APP SVR) via the Client (APP). Because the delivery path passes through the client side, sessionKey must be transmitted in ciphertext form to ensure security.
After the APP SVR receives encrypted_session_key, it must decrypt it according to this guide to obtain the real sessionKey. This key will be used in subsequent business flows to encrypt the user's sensitive information. For details, refer to:
1. Prerequisites
Before starting integration, make sure the following preparation is complete:
- Configure the data symmetric encryption key: You need to configure the symmetric key in the SUD OpenPaaS admin console (see Data Security Key Reference). The current algorithm is AES-256-GCM, with a 32-byte (256-bit) key configured as Base64 encoding. Keep this key safe.
2. Decryption and Verification Flow
1. Base64-decode the data
Decode the obtained encrypted_session_key (a Base64 string) into binary data (byte array / Buffer).
2. Split the data
The decoded binary ciphertext data has a fixed structure in the following concatenated format:
+----------------+-------------------+-------------------+
| IV (12 bytes) | ciphertext (var) | auth tag (16 bytes) |
+----------------+-------------------+-------------------+IV: initialization vector, 12 bytes
Ciphertext: the encrypted payload data, variable length
Auth tag: the authentication information of GCM mode, 16 bytes
3. Decrypt and authenticate
Decrypt the ciphertext with AES-256-GCM using the same data symmetric encryption key, IV, and auth tag.
On successful decryption, the original JSON string payload is returned.
On decryption failure, the data is invalid or has been tampered with.
4. Validate the payload content
After decryption you get a JSON string containing the following fields:
{"user_id":"xxx","session_key":"xxx"}| Parameter | Required | Type | Description |
|---|---|---|---|
| user_id | Yes | string | The user's unique identifier ID |
| session_key | Yes | string | Session key |
Parameter validation rules:
user_id: verify whether the decrypteduser_idmatches the user ID of the current request;session_key: the session key for subsequent business interactions; it must be stored securely on the server and must not be delivered to the client.
3. Example Code
Complete example code (including Base64 decoding, splitting IV/ciphertext/tag, AES-256-GCM decryption, and payload field validation) is available in the "2. sessionKey Decryption" section of each language version under Example Code.
4. Common Troubleshooting
Common causes of decryption failure
- Key mismatch: the key used for decryption is not the same as the one used for encryption.
- Malformed data: Base64 decoding fails, or the data length is less than 12+16 bytes.
- Wrong auth tag: the data has been tampered with, the tag was extracted from the wrong position, or GCM authentication failed.
- Inconsistent IV length: not split as 12 bytes.
- Cross-language compatibility issues: the concatenation order must be strictly IV + ciphertext + tag.
