UserSig is a password that is used to log in to IM. It is the ciphertext that results from encrypting certain data such as UserID. This document describes how to generate a UserSig.
Store the key information properly so as to prevent leaks.
GenerateTestUserSig open-source module provided in the sample code of the IM SDK can help you quickly generate a UserSig. You only need to configure three member variables, SDKAPPID (SDKAppID of the app), EXPIRETIME (UserSig expiration time), and SECRETKEY (key information), and then call the genTestUserSig() function to quickly obtain a UserSig.
To simplify this process, we provide the source code for computing a UserSig for the following languages and platforms. You can directly download and integrate the source code into your client.
|Programming Language||Platform||GenerateTestUserSig Source Code|
In this method, the SECRETKEY is easy to decompile and reverse engineer. If the SECRETKEY is leaked, hackers can steal your Tencent Cloud traffic. Therefore, this method is used only to locally run through a demo project and debug features.
The correct way to issue a UserSig is to integrate the UserSig calculation code snippet into your server and provide app-oriented APIs. When UserSig is needed, your app will send a request to the business server to obtain a dynamic UserSig. For more information, see Generating a UserSig on the Server.
Generating a UserSig on the server provides maximum protection against the disclosure of the key used for calculating the UserSig. You only need to deploy the code for calculating the UserSig on your server and provide an app-oriented API. When a UserSig is needed, your app will send a request to the business server to obtain a dynamic UserSig.
To simplify this process, we provide the source code for computing a UserSig for the following languages and platforms. You can directly download and integrate the source code into your server.
|Programming Language||Key Function||Download Link|
The calculation function of UserSig uses key parameters like SDKAppID, UserID, and the UserSig validity period. The key parameters are described in detail in the following list.
The list below uses Java as an example, and the field names may vary depending on the actual language.
|Field Name||Parameter Description|
|sdkappid||SDKAppID of the app, which can be obtained from the corresponding app card in the IM console|
|userId||User ID, formerly known as Identifier|
|expire||Validity period of the UserSig in seconds|
|userbuf||IM uses APIs without UserBuf by default, which this parameter is set to
You may need to use APIs with UserBuf for some TRTC scenarios, such as joining a room. For more information, see Configuring Permissions for Entering a Room.
|key||Information of the key, which can be obtained from the app details page in the IM console. For details, see Getting the key.|
To simplify signature calculation so that users can conveniently and quickly use Tencent Cloud services, the signature algorithm of the IM service has been upgraded from ECDSA-SHA256 to HMAC-SHA256 since July 19, 2019. This means that all SDKAppIDs created after July 19, 2019 will use the new HMAC-SHA256 algorithm.
If your SDKAppID was created before July 19, 2019, we recommend that you upgrade its signature algorithm to the HMAC-SHA256 Algorithm. The upgrade will not affect your current businesses. Alternatively, you can still use the signature algorithm of an earlier version. The URLs for downloading the source code of the ECDSA-SHA256 algorithm for different languages are as follows: