UserSig is a security signature designed by Tencent Cloud to prevent attackers from accessing your Tencent Cloud account.
Currently, Tencent Cloud services including TRTC, IM, and MLVB all use this security mechanism. Whenever you want to use these services, you must provide three key pieces of information, i.e.
UserSig in the initialization or login function of the corresponding SDK.
SDKAppID is used to identify your application, and
UserID your user.
UserSig is a security signature calculated based on the two parameters using the HMAC SHA256 encryption algorithm. Attackers cannot use your Tencent Cloud traffic without authorization as long as they cannot forge a
See the figure below for how
UserSig is calculated. Basically, it involves hashing crucial information such as
// UserSig formula, in which `secretkey` is the key used to calculate UserSig usersig = hmacsha256(secretkey, (userid + sdkappid + currtime + expire + base64(userid + sdkappid + currtime + expire)))
currtimeis the current system time and
expirethe expiration time of the signature.
- The above figure only shows how to calculate
UserSig. For more information on how to implement the
UserSigconcatenation code, please see Calculating
UserSigthrough client sample code and How do I calculate
UserSigduring formal operations?.
UserSigduring debugging and running?
- The above methods for calculating and getting
UserSigare only applicable for debugging. They are not recommended for official launch because
SECRETKEYof the client code (especially on the web) may be easily decompiled and reversed. If your key is leaked, attackers can steal your Tencent Cloud traffic.
- The correct method is to deploy the
UserSigcalculation code on your project server so that your application can request from your server a
UserSigthat is calculated whenever one is needed.
UserSigthrough client sample code
SDKAppIDand click the Quick Start tab.
UserSigin Step 2: obtain the secret key to issue UserSig.
If you can get only the public and private key information when you try to view the secret key, see Only public and private key can be obtained when I try to view the secret key. How do I get the secret key?.
UserSigfor various platforms, which you can directly download for calculation:
|Applicable Platform||File Source Code||Relative File Path|
|WeChat Mini Program||Github||WXMini/TRTCSimpleDemo/debug/GenerateTestUserSig.js|
TRTC SDK 6.6 (August 2019) and later versions use the new signature algorithm HMAC-SHA256. If your application was created before August 2019, you need to upgrade the signature algorithm to get a new key. Without upgrading, you can continue to use the old algorithm ECDSA-SHA256. After upgrading, you can switch between the new and old algorithms as needed.
During production, TRTC provides a more secure scheme of using the server to calculate
UserSig. It offers the utmost protection against key leakage, for it is more difficult to hack a server than it is to reverse engineer an application. See below for the specific implementation process:
UserSigfrom your server.
UserSigbased on the
UserID. The calculation source code is provided above.
UserSigto your application.
UserSigto the SDK through a specific API.
SDKAppID + UserID + UserSigto the Tencent Cloud server for verification.
UserSigis valid, real time audio/video services will be provided to the TRTC SDK.
To simplify your implementation process, we provide
UserSig calculation source code in multiple languages (new signature algorithm):
|Programming Language||Signature Algorithm||Key Function||Download Link|
To simplify the signature calculation process and facilitate your use of Tencent Cloud services, on July 19, 2019, TRTC switched from ECDSA-SHA256 to the new signature algorithm HMAC-SHA256. This means that all applications (
SDKAppID) created on and after July 19, 2019 will use the new HMAC-SHA256 algorithm.
If your application (
SDKAppID) was created before July 19, 2019, you can continue to use the old signature algorithm, whose source code can be downloaded in the below links.
|Programing Language||Signature Algorithm||Download Link|