public class Sign extends Object
Constructor and Description |
---|
Sign() |
Modifier and Type | Method and Description |
---|---|
protected static String |
buildParamStr(TreeMap<String,String> requestParams,
String requestMethod)
Builds the parameter string for signing, formatting the parameters in a query string format.
|
static byte[] |
hmac256(byte[] key,
String msg)
Calculates the HMAC-SHA-256 signature of the given message using the specified key.
|
static String |
makeSignPlainText(TreeMap<String,String> requestParams,
String reqMethod,
String host,
String path)
Constructs the plain text string for signing.
|
static String |
sha256Hex(byte[] b)
Calculates the SHA-256 hash of the given byte array and returns it as a hexadecimal string.
|
static String |
sha256Hex(String s)
Calculates the SHA-256 hash of the given string and returns it as a hexadecimal string.
|
static String |
sign(String secretKey,
String sigStr,
String sigMethod)
Signs the given string using the specified method and secret key.
|
public static String sign(String secretKey, String sigStr, String sigMethod) throws TencentCloudSDKException
secretKey
- The secret key used to generate the signature.sigStr
- The string to sign.sigMethod
- The signing method (e.g., "HmacSHA256").TencentCloudSDKException
- If there is an error during signing.public static String makeSignPlainText(TreeMap<String,String> requestParams, String reqMethod, String host, String path)
requestParams
- The request parameters to include in the string.reqMethod
- The HTTP request method (GET, POST, etc.).host
- The host (API endpoint).path
- The request path.protected static String buildParamStr(TreeMap<String,String> requestParams, String requestMethod)
requestParams
- The request parameters to include in the string.requestMethod
- The HTTP request method (GET, POST, etc.).public static String sha256Hex(String s) throws TencentCloudSDKException
s
- The string to hash.TencentCloudSDKException
- If SHA-256 is not supported.public static String sha256Hex(byte[] b) throws TencentCloudSDKException
b
- The byte array to hash.TencentCloudSDKException
- If SHA-256 is not supported.public static byte[] hmac256(byte[] key, String msg) throws TencentCloudSDKException
key
- The key to use for HMAC.msg
- The message to sign.TencentCloudSDKException
- If HMAC-SHA-256 is not supported.Copyright © 2025. All rights reserved.