OSS supports server-side encryption (SSE). When you upload data, OSS encrypts and stores the data. When you download the data, OSS automatically decrypts it and returns the raw data. The HTTP response header indicates that the data was encrypted on the server.
Notes
Before you configure server-side encryption, make sure you understand the feature. For more information, see Server-side encryption.
The sample code in this topic uses the China (Hangzhou) region ID
cn-hangzhouand a public endpoint. If you access OSS from another Alibaba Cloud service in the same region, use an internal endpoint. For more information about OSS regions and endpoints, see Regions and endpoints.This topic uses environment variables to read access credentials. For more information about how to configure access credentials, see Configure access credentials.
To configure bucket encryption, you must have the
oss:PutBucketEncryptionpermission. To retrieve bucket encryption configurations, you must have theoss:GetBucketEncryptionpermission. To delete bucket encryption configurations, you must have theoss:DeleteBucketEncryptionpermission. For more information, see Grant custom access policies to RAM users.
Sample code
References
For the complete sample code for server-side encryption, see put_bucket_encryption.go, get_bucket_encryption.go, and delete_bucket_encryption.go.
For more information about the API operation to configure server-side encryption, see PutBucketEncryption.
For more information about the API operation to retrieve server-side encryption configurations, see GetBucketEncryption.
For more information about the API operation to delete server-side encryption configurations, see DeleteBucketEncryption.