Server-side encryption for uploaded data is supported. When you upload data, OSS encrypts the received data and stores the encrypted data. When you download the encrypted data, OSS automatically decrypts the data, returns the original data to you, and declares in the header of the response that the data had been encrypted on the server.
Notes
Make sure that you are familiar with this feature before you configure server-side encryption. For more information, see server-side encryption.
The sample code in this topic uses the region ID of the China (Hangzhou) region. By default, the public endpoint is used to access resources in a bucket. If you want to access resources in the bucket by using other Alibaba Cloud services in the same region in which the bucket is located, use an internal endpoint. For more information about supported regions and endpoints, see OSS regions and endpoints.
In this topic, access credentials are obtained from environment variables. For more information about how to configure access credentials, see Configure access credentials.
The
oss:PutBucketEncryption
permission is required for the configuration of server-side encryption for a bucket. Theoss:GetBucketEncryption
permission is required for querying the server-side encryption configurations of a bucket. Theoss:DeleteBucketEncryption
permission is required for deleting the server-side encryption configurations of a bucket. For more information, see Grant custom policy to RAM users.
Sample code
References
For the complete sample code that is used to perform server-side encryption, visit put_bucket_encryption.go, get_bucket_encryption.go, and delete_bucket_encryption.go.
For more information about the API operation that you can call to configure server-side encryption, see PutBucketEncryption.
For more information about the API operation that you can call to query the server-side encryption configurations, see GetBucketEncryption.
For more information about the API operation that you can call to delete server-side encryption configurations, see DeleteBucketEncryption.