tencent cloud

Cloud Object Storage

Release Notes and Announcements
Release Notes
Announcements
Product Introduction
Overview
Features
Use Cases
Strengths
Concepts
Regions and Access Endpoints
Specifications and Limits
Service Regions and Service Providers
Billing
Billing Overview
Billing Method
Billable Items
Free Tier
Billing Examples
Viewing and Downloading Bill
Payment Overdue
FAQs
Getting Started
Console
Getting Started with COSBrowser
User Guide
Creating Request
Bucket
Object
Data Management
Batch Operation
Global Acceleration
Monitoring and Alarms
Operations Center
Data Processing
Content Moderation
Smart Toolbox
Data Processing Workflow
Application Integration
User Tools
Tool Overview
Installation and Configuration of Environment
COSBrowser
COSCLI (Beta)
COSCMD
COS Migration
FTP Server
Hadoop
COSDistCp
HDFS TO COS
GooseFS-Lite
Online Tools
Diagnostic Tool
Use Cases
Overview
Access Control and Permission Management
Performance Optimization
Accessing COS with AWS S3 SDK
Data Disaster Recovery and Backup
Domain Name Management Practice
Image Processing
Audio/Video Practices
Workflow
Direct Data Upload
Content Moderation
Data Security
Data Verification
Big Data Practice
COS Cost Optimization Solutions
Using COS in the Third-party Applications
Migration Guide
Migrating Local Data to COS
Migrating Data from Third-Party Cloud Storage Service to COS
Migrating Data from URL to COS
Migrating Data Within COS
Migrating Data Between HDFS and COS
Data Lake Storage
Cloud Native Datalake Storage
Metadata Accelerator
GooseFS
Data Processing
Data Processing Overview
Image Processing
Media Processing
Content Moderation
File Processing Service
File Preview
Troubleshooting
Obtaining RequestId
Slow Upload over Public Network
403 Error for COS Access
Resource Access Error
POST Object Common Exceptions
API Documentation
Introduction
Common Request Headers
Common Response Headers
Error Codes
Request Signature
Action List
Service APIs
Bucket APIs
Object APIs
Batch Operation APIs
Data Processing APIs
Job and Workflow
Content Moderation APIs
Cloud Antivirus API
SDK Documentation
SDK Overview
Preparations
Android SDK
C SDK
C++ SDK
.NET(C#) SDK
Flutter SDK
Go SDK
iOS SDK
Java SDK
JavaScript SDK
Node.js SDK
PHP SDK
Python SDK
React Native SDK
Mini Program SDK
Error Codes
Harmony SDK
Endpoint SDK Quality Optimization
Security and Compliance
Data Disaster Recovery
Data Security
Cloud Access Management
FAQs
Popular Questions
General
Billing
Domain Name Compliance Issues
Bucket Configuration
Domain Names and CDN
Object Operations
Logging and Monitoring
Permission Management
Data Processing
Data Security
Pre-signed URL Issues
SDKs
Tools
APIs
Agreements
Service Level Agreement
Privacy Policy
Data Processing And Security Agreement
Contact Us
Glossary

Server-Side Encryption

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 2024-02-01 18:01:21

Overview

You can encrypt uploaded objects in the following ways.

Using SSE-COS Encryption

Description

With this method, your master key and data are managed by COS. COS can automatically encrypt your data when written into the IDC and automatically decrypt it when accessed. Currently, COS supports AES-256 encryption using a COS master key pair.
In the C SDK, you need to configure the encryption by specifying the x-cos-server-side-encryption header.

Sample

int main(int argc, char *argv[])
{
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_table_t *resp_headers = NULL;
cos_table_t *headers = NULL;
cos_string_t file;
cos_string_t download_file;
// Initialize
if (cos_http_io_initialize(NULL, 0) != COSE_OK) {
exit(1);
}
cos_pool_create(&p, NULL);
// Initialize the request options
options = cos_request_options_create(p);
options->config = cos_config_create(options->pool);
cos_str_set(&options->config->endpoint, "cos.ap-guangzhou.myqcloud.com"); // Your endpoint
cos_str_set(&options->config->access_key_id, "SECRETID");// Your SecretId
cos_str_set(&options->config->access_key_secret, "SECRETKEY"); // Your SecretKey
cos_str_set(&options->config->appid, "APPID");// Your APPID
options->config->is_cname = is_cname;
options->ctl = cos_http_controller_create(options->pool, 0);
cos_str_set(&bucket, "<BucketName-APPID>");// Your bucket name in the format: BucketName-APPID

// Set headers for server-side SSE-COS encryption
headers = cos_table_make(p, 1);
apr_table_add(headers, "x-cos-server-side-encryption", "AES256");

cos_str_set(&file, "example1.txt");// Your filename
cos_str_set(&object, "example_object");// Your object name

// Upload an object
s = cos_put_object_from_file(options, &bucket, &object, &file, headers, &resp_headers);
if (cos_status_is_ok(s)) {
printf("put object succeeded\\n");
} else {
printf("put object failed\\n");
}

// Download an object
cos_str_set(&download_file, "example2.txt");
s = cos_get_object_to_file(options, &bucket, &object, NULL, NULL, &download_file, &resp_headers);
if (cos_status_is_ok(s)) {
printf("get object succeeded\\n");
} else {
printf("get object failed\\n");
}

cos_pool_destroy(p);

cos_http_io_deinitialize();
return 0;
}

Using SSE-C Encryption

The encryption key is provided by the customer. When you upload an object, COS will apply AES-256 encryption to your data using the customer-provided encryption key pair. In the C SDK, you need to configure the encryption by specifying the x-cos-server-side-encryption-customer-* header.

Description

Note:
This type of encryption requires using HTTPS requests.
customerKey: the key provided by the user; this key should be a 32-byte string consisting of numbers, letters, and symbols. Chinese characters are not supported.
If this encryption method was used when you uploaded the source file, you should also use it when you GET (download) or HEAD (query) this file.

Sample

int main(int argc, char *argv[])
{
cos_pool_t *p = NULL;
int is_cname = 0;
cos_status_t *s = NULL;
cos_request_options_t *options = NULL;
cos_string_t bucket;
cos_string_t object;
cos_table_t *resp_headers = NULL;
cos_table_t *headers = NULL;
cos_string_t file;
cos_string_t download_file;
// Initialize
if (cos_http_io_initialize(NULL, 0) != COSE_OK) {
exit(1);
}
cos_pool_create(&p, NULL);
// Initialize the request options
options = cos_request_options_create(p);
options->config = cos_config_create(options->pool);
cos_str_set(&options->config->endpoint, "https://cos.ap-guangzhou.myqcloud.com"); // Your endpoint, which requires requests to be sent over HTTPS
cos_str_set(&options->config->access_key_id, "SECRETID");// Your SecretId
cos_str_set(&options->config->access_key_secret, "SECRETKEY"); // Your SecretKey
cos_str_set(&options->config->appid, "APPID");// Your APPID
options->config->is_cname = is_cname;
options->ctl = cos_http_controller_create(options->pool, 0);
cos_str_set(&bucket, "<BucketName-APPID>");// Your bucket name in the format: BucketName-APPID

// Set headers for SSE-C encryption
headers = cos_table_make(p, 3);
apr_table_add(headers, "x-cos-server-side-encryption-customer-algorithm", "AES256");
apr_table_add(headers, "x-cos-server-side-encryption-customer-key", "MDEyMzQ1Njc4OUFCQ0RFRjAxMjM0NTY3ODlBQkNERUY=");// Replace with your own Base64-encoded server-side encryption key
apr_table_add(headers, "x-cos-server-side-encryption-customer-key-MD5", "U5L61r7jcwdNvT7frmUG8g==");// Replace with the Base64-encoded MD5 hash of your own server-side encryption key

cos_str_set(&file, "example1.txt");// Your file name
cos_str_set(&object, "example_object");// Your object name

// Upload an object
s = cos_put_object_from_file(options, &bucket, &object, &file, headers, &resp_headers);
if (cos_status_is_ok(s)) {
printf("put object succeeded\\n");
} else {
printf("put object failed\\n");
}

// Download an object, which also requires the headers for server-side encryption
cos_str_set(&download_file, "example2.txt");
s = cos_get_object_to_file(options, &bucket, &object, headers, NULL, &download_file, &resp_headers);
if (cos_status_is_ok(s)) {
printf("get object succeeded\\n");
} else {
printf("get object failed\\n");
}

cos_pool_destroy(p);

cos_http_io_deinitialize();
return 0;
}

Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan