This document describes how to enable server-side encryption when uploading objects. There are three types of keys that can be used for server-side encryption:
For parameters and method description of all APIs in the SDK, please see SDK API Reference.
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.
Objective-C
QCloudCOSXMLUploadObjectRequest *request = [QCloudCOSXMLUploadObjectRequest new];
[request setCOSServerSideEncyption];
Note:For the complete sample, go to GitHub.
Swift
request.setCOSServerSideEncyption();
Note:For the complete sample, go to GitHub.
With this method, the encryption key is provided by the customer. To upload an object, COS will apply AES-256 encryption to the data using the customer-provided encryption key pair.
Note:
- This type of encryption requires using HTTPS requests.
- You need to provide a 32-byte string as the key, a combination of numbers, letters, and characters, with Chinese characters not supported.
- If a file was key-encrypted when uploaded, you need to include the same key in your GET (download) or HEAD (query) request for it to succeed.
Objective-C
QCloudCOSXMLUploadObjectRequest *request = [QCloudCOSXMLUploadObjectRequest new];
NSString *customKey = @"123456qwertyuioplkjhgfdsazxcvbnm";
[request setCOSServerSideEncyptionWithCustomerKey:customKey];
Note:For the complete sample, go to GitHub.
Swift
let customKey = "123456qwertyuioplkjhgfdsazxcvbnm";
request.setCOSServerSideEncyptionWithCustomerKey(customKey);
Note:For the complete sample, go to GitHub.
SSE-KMS encryption is server-side encryption using keys managed by KMS, a Tencent Cloud security management service. KMS is designed to generate and protect your keys using third party–certified hardware security modules (HSM). It allows you to easily create and manage keys for use in multiple applications and services, while meeting regulatory and compliance requirements. For information on how to activate KMS service, see Server-side Encryption Overview.
Objective-C
QCloudCOSXMLUploadObjectRequest *request = [QCloudCOSXMLUploadObjectRequest new];
NSString *customKey = @"123456qwertyuioplkjhgfdsazxcvbnm";
NSString *arrJsonStr = @"{\"key\":\"value\"}";
[request setCOSServerSideEncyptionWithKMSCustomKey:customKey jsonStr:arrJsonStr];
Note:For the complete sample, go to GitHub.
Swift
let customKey = "123456qwertyuioplkjhgfdsazxcvbnm";
let arrJsonStr = "{\"key\":\"value\"}";
self.advancedRequest?.setCOSServerSideEncyptionWithKMSCustomKey(customKey, jsonStr: arrJsonStr);
Note:For the complete sample, go to GitHub.
Was this page helpful?