tencent cloud

Feedback

Authentication Key

Last updated: 2024-01-18 11:56:22
    This document describes the authentication key for all platforms to help you integrate and debug GME.

    Backend Deployment of Voice Key

    GME provides authentication keys for voice chat and offline voice. This document describes the backend deployment scheme. The generation process of the signature used for authentication involves plaintext, secret key and algorithm.

    Plaintext

    The plaintext is the concatenation of the following fields in endian byte order:
    Field
    Type/Length
    Description
    cVer
    unsigned char(1)
    Version number. Enter 1.
    wOpenIDLen
    unsigned short(2)
    User account length
    strOpenID
    string
    User account's characters
    dwSdkAppid
    unsigned short(4)
    SDKappid of the developer
    dwReserved1
    unsigned int(4)
    Enter 0.
    dwExpTime
    unsigned int(4)
    Expiration time (current time + validity period) in seconds. 300 is recommended.
    dwReserved2
    unsigned int(4)
    Enter -1 or 0xFFFFFFFF.
    dwReserved3
    unsigned int(4)
    Enter 0.
    wRoomIDLen
    unsigned short(2)
    Length of the ID of the room to enter. Enter 0 for the voice messaging service.
    strRoomID
    string
    Characters of the ID of the room to enter

    Key

    Get the relevant permission key in the GME console.

    Algorithm

    The Tiny Encryption Algorithm (TEA) symmetric algorithm is used. Generally, we recommend that you use the client deployment scheme in the initial stage, which later can be optimized for deployment on the game application's backend.
    Scheme
    Pros
    Cons
    Backend deployment
    High security
    Backend development and joint testing required
    Client deployment
    Quick integration
    Low security

    Backend Deployment

    The encrypted string generated on the backend is sent to the client and used for the following scenario: When the EnterRoom API is called for entering a room, the encrypted string will be transferred to the authBuffer field in the parameters for room entering.

    Algorithm Encryption Details

    Key: Authentication key of APPID.
    Encryption algorithm: TEA.
    Note:
    Change of the key in the console takes effect within 15 minutes to 1 hour. We recommend that you not change it frequently.

    Encryption method

    1. Reorganize the numbers in the plaintext in endian order.
    2. Concatenate the plaintext fields into a string in the sequence how they are declared.
    3. Encrypt the concatenated string with TEA. The string output by the symmetry_encrypt function is the permission encryption string.
    Note:
    Do not convert a binary string into a hexadecimal one.

    Sample code

    Taking C++ as an example, below is the sample code of the authentication key:
    unsigned char pInBuf[512]={0};
    xel::byte_writer bw(pInBuf, sizeof(pInBuf));
    
    char cVer = 1;
    unsigned short wOpenIDLen = (unsigned short)strlen((const char *)strOpenID);
    if (wOpenIDLen > 127) wOpenIDLen = 127;
    unsigned short wRoomIDLen = (unsigned short)strlen((const char *)strRoomID);
    if (wRoomIDLen > 127) wRoomIDLen = 127;
    
    bw.write_byte(cVer);
    bw.write_int16(wOpenIDLen);
    bw.write_bytes(strOpenID, wOpenIDLen);
    bw.write_int32(dwSdkAppId);
    bw.write_int32(0 /*dwRoomID*/);
    bw.write_int32(expTime);
    bw.write_int32(nAuthBits);
    bw.write_int32(0 /*dwAccountType*/);
    bw.write_int16(wRoomIDLen);
    bw.write_bytes(strRoomID, wRoomIDLen);
    
    int pInLen = bw.bytes_write();
    
    unsigned char pEncryptOutBuf[512] = { 0 };
    int iEncrptyLen = 0;
    
    symmetry_encrypt((const unsigned char*)pInBuf, pInLen, (const unsigned char*)key, (unsigned char*)pEncryptOutBuf, &iEncrptyLen);
    You can also download the sample code in Java and Go here.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support