| Crates.io | tencentcloud-sign-sdk |
| lib.rs | tencentcloud-sign-sdk |
| version | 0.1.0 |
| created_at | 2025-09-14 06:38:29.607343+00 |
| updated_at | 2025-09-14 06:38:29.607343+00 |
| description | TencentCloud Sign SDK for Rust - Common signing utilities for TencentCloud APIs |
| homepage | https://github.com/y-zion/tencentcloud-sign-sdk-rust |
| repository | https://github.com/y-zion/tencentcloud-sign-sdk-rust |
| max_upload_size | |
| id | 1838388 |
| size | 36,476 |
A common signing library for TencentCloud APIs, providing the TC3-HMAC-SHA256 algorithm used across all TencentCloud services.
Add this to your Cargo.toml:
[dependencies]
tencentcloud-sign-sdk = "0.1.0"
use tencentcloud_sign_sdk::{Tc3Signer, sha256_hex};
use time::OffsetDateTime;
// Create a signer
let signer = Tc3Signer::new(
"your_secret_id".to_string(),
"your_secret_key".to_string(),
"hunyuan".to_string(), // service name
false, // debug mode
);
// Prepare request data
let method = "POST";
let canonical_uri = "/";
let canonical_querystring = "";
let canonical_headers = "content-type:application/json; charset=utf-8\nhost:example.com\n";
let signed_headers = "content-type;host";
let payload = r#"{"message":"hello"}"#;
let hashed_payload = sha256_hex(payload);
let timestamp = OffsetDateTime::now_utc().unix_timestamp();
// Sign the request
let result = signer.sign(
method,
canonical_uri,
canonical_querystring,
canonical_headers,
signed_headers,
&hashed_payload,
timestamp,
);
// Create Authorization header
let auth_header = signer.create_authorization_header(&result, signed_headers);
use tencentcloud_sign_sdk::{sha256_hex, hmac_sha256_hex};
// SHA256 hashing
let hash = sha256_hex("hello world");
// HMAC-SHA256 signing
let key = b"secret_key";
let data = "message to sign";
let signature = hmac_sha256_hex(key, data);
The main signer class for TC3-HMAC-SHA256 algorithm.
new(secret_id, secret_key, service, debug) - Create a new signersign(...) - Sign a request and return signature detailscreate_authorization_header(result, signed_headers) - Create Authorization headersecret_id() - Get the secret IDservice() - Get the service namedebug() - Check if debug mode is enabledsha256_hex(data) - Compute SHA256 hash as hex stringhmac_sha256(key, data) - Compute HMAC-SHA256 as raw byteshmac_sha256_hex(key, data) - Compute HMAC-SHA256 as hex stringThis project uses the license provided in LICENSE.
Contributions are welcome! Please feel free to submit a Pull Request.