UserSig
?UserSig
is a security signature designed by Tencent Cloud to prevent attackers from accessing your Tencent Cloud account.
Currently, Tencent Cloud services including TRTC, Chat, and MLVB all use this security mechanism. To use these services, you must pass in three parameters – SDKAppID
, UserID
, and UserSig
– to the initialization or login API of the corresponding SDK.
SDKAppID
identifies an application, and UserID
identifies a user. UserSig
is a security signature calculated based on SDKAppID
and UserID
using the HMAC SHA256 encryption algorithm. Attackers cannot use your Tencent Cloud traffic as long as they don’t have UserSig
.
See the figure below for how UserSig
is calculated. Basically, it involves hashing crucial information such as SDKAppID
, UserID
, and ExpireTime
.// UserSig formula, in which `secretkey` is the key used to calculate UserSigusersig = hmacsha256(secretkey, (userid + sdkappid + currtime + expire +base64(userid + sdkappid + currtime + expire)))
currtime
is the current system time and expire
the expiration time of the signature.UserSig
. For more information on the code used to generate UserSig
, see Calculating UserSig
using client-side sample code or Generating UserSig
in the console.UserSig
during debugging or demo run?UserSig
either using our client-side sample code or in the console:SECRETKEY
in 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.UserSig
calculation code on your project server so that your application can request from your server a UserSig
that is calculated whenever one is needed.UserSig
using client-side sample codeSDKAppID
and key:
1. Log in to the TRTC console and click Application Management.
2. Find your application and click Configuration.
3. In Basic information, SDKSecretKey is the key used to calculate UserSig
.
4. Copy the key.
UserSig
:
We offer source code for calculating UserSig
on different platforms.Platform | Code | Relative Path |
iOS | TRTC-API-Example-OC/Debug/GenerateTestUserSig.h | |
macOS | OCDemo/TRTCDemo/TRTC/GenerateTestUserSig.h | |
Android | TRTC-API-Example/Debug/src/main/java/com/tencent/trtc/debug/GenerateTestUserSig.java | |
Windows (C++) | TRTC-API-Example-C++/TRTC-API-Example-Qt/src/Util/defs.h | |
Windows (C#) | TRTC-API-Example-CSharp/TRTC-API-Example-CSharp/GenerateTestUserSig.cs | |
Web | base-js/js/debug/GenerateTestUserSig.js | |
Flutter | TRTC-API-Example/lib/Debug/GenerateTestUserSig.dart |
GenerateTestUserSig
in the TRTC SDK sample code. Set the three member variables of SDKAPPID
, EXPIRETIME
, and SECRETKEY
, and you will be able to call genTestUserSig()
to obtain the UserSig
and get started quickly.
UserSig
in the consoleSDKAppID
) from the drop-down list. A secret key will be generated automatically.UserSig
in a production environment?UserSig
calculation offers stronger protection against key leakage because it is more difficult to hack a server than it is to reverse engineer an application. See below for detailed directions:UserSig
from your server.UserSig
based on the SDKAppID
and UserID
. The calculation source code is provided above.UserSig
to your application.UserSig
to the SDK through a specific API.SDKAppID + UserID + UserSig
to the Tencent Cloud server for verification.UserSig
.UserSig
is valid, services will be provided to the TRTC SDK.UserSig
calculation source code (new algorithm) in multiple languages.UserSig
calculation source code using the legacy algorithmSDKAppID
) created on and after July 19, 2019 will use the new HMAC-SHA256 algorithm.SDKAppID
) was created before July 19, 2019, you can continue to use the old signature algorithm, whose source code can be downloaded below.
Was this page helpful?