Tüm Ürünler
Search
Belge Merkezi

Object Storage Service:Server-side encryption (OSS SDK for Python 1.0)

Son Güncelleme:Oct 01, 2026

Object Storage Service (OSS), yüklenen verileri sunucu tarafında şifreleyebilir. Buna sunucu tarafı şifreleme denir. Verileri OSS'e yüklediğinizde OSS bu verileri şifreler ve şifrelenmiş haliyle kalıcı olarak depolar. OSS'ten veri indirdiğinizde OSS verilerin şifresini çözer ve çözümlemiş verileri döndürür. Ayrıca yanıt başlığına, verilerin sunucuda şifrelendiğini belirten bir alan eklenir.

Notlar

  • Sunucu tarafı şifrelemeyi yapılandırmadan önce bu özelliği iyice tanıdığınızdan emin olun. Daha fazla bilgi için bkz. Sunucu tarafı şifreleme.

  • Bu konuda Çin (Hangzhou) bölgesinin genel uç noktası kullanılmıştır. OSS ile aynı bölgedeki diğer Alibaba Cloud hizmetlerinden OSS'e erişmek istiyorsanız dahili bir uç nokta kullanın. OSS bölgeleri ve uç noktaları hakkında daha fazla bilgi için bkz. Bölgeler ve uç noktalar.

  • Bu konuda erişim kimlik bilgileri ortam değişkenlerinden alınır. Erişim kimlik bilgilerinin nasıl yapılandırılacağı hakkında daha fazla bilgi için bkz. OSS SDK for Python 1.0 kullanarak erişim kimlik bilgilerini yapılandırma.

  • Bu konu, bir OSS uç noktası ile bir OSSClient örneğinin nasıl oluşturulacağını göstermektedir. Özel etki alanı kullanma veya Security Token Service (STS) kimlik bilgileriyle kimlik doğrulama gibi alternatif yapılandırmalar için bkz. Başlatma.

  • Bir paket için sunucu tarafı şifrelemeyi yapılandırmak üzere oss:PutBucketEncryption iznine sahip olmanız gerekir. Bir paketin sunucu tarafı şifreleme yapılandırmalarını sorgulamak için oss:GetBucketEncryption iznine sahip olmanız gerekir. Bir paketin sunucu tarafı şifreleme yapılandırmalarını silmek için oss:DeleteBucketEncryption iznine sahip olmanız gerekir. Daha fazla bilgi için bkz. Özel ilke atama.

Paket için sunucu tarafı şifrelemeyi yapılandırma

Aşağıdaki örnek kod, bir paket için varsayılan bir şifreleme yönteminin nasıl yapılandırılacağını göstermektedir. Varsayılan şifreleme yöntemini yapılandırdıktan sonra, şifreleme yöntemi belirtilmeden pakete yüklenen tüm nesneler varsayılan şifreleme yöntemi kullanılarak şifrelenir.

# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
from oss2.models import ServerSideEncryptionRule
# Obtain access credentials from the environment variables. Before you run the sample code, make sure that you have configured environment variables OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET. 
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
# Specify the ID of the region that maps to the endpoint. Example: cn-hangzhou. This parameter is required if you use the signature algorithm V4.
region = "cn-hangzhou"

# Specify the name of the bucket.
bucket = oss2.Bucket(auth, endpoint, "examplebucket", region=region)

# Create encryption configurations for the bucket. In this example, AES-256 encryption is used. 
rule = ServerSideEncryptionRule()
rule.sse_algorithm = oss2.SERVER_SIDE_ENCRYPTION_AES256
# Specify the CMK ID. The CMK ID can be specified only if you use the OSS-KMS encryption method. If you want to use a specified CMK for encryption, enter the CMK ID. If you want to use the default CMK managed by KMS for encryption, leave this parameter empty. If you use AES-256 encryption, you must leave this parameter empty. 
rule.kms_master_keyid = ""

# Apply the encryption configurations to the bucket. 
result = bucket.put_bucket_encryption(rule)

# Display the returned HTTP status code. 
print('http response code:', result.status)

Paketin sunucu tarafı şifreleme yapılandırmalarını sorgulama

Aşağıdaki örnek kod, bir paketin sunucu tarafı şifreleme yapılandırmalarının nasıl sorgulanacağını göstermektedir:

# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
# Obtain access credentials from the environment variables. Before you run the sample code, make sure that you have configured environment variables OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET. 
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
# Specify the ID of the region that maps to the endpoint. Example: cn-hangzhou. This parameter is required if you use the signature algorithm V4.
region = "cn-hangzhou"

# Specify the name of the bucket.
bucket = oss2.Bucket(auth, endpoint, "examplebucket", region=region)

# Query the server-side encryption configurations of the bucket. 
result = bucket.get_bucket_encryption()
# Display the obtained server-side encryption configurations. 
print('sse_algorithm:', result.sse_algorithm)
print('kms_master_keyid:', result.kms_master_keyid) # If the encryption method is AES256, set kms_master_keyid to None.

Paketin sunucu tarafı şifreleme yapılandırmalarını silme

Aşağıdaki örnek kod, bir paketin sunucu tarafı şifreleme yapılandırmalarının nasıl silineceğini göstermektedir:

# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
# Obtain access credentials from the environment variables. Before you run the sample code, make sure that you have configured environment variables OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET. 
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
# Specify the ID of the region that maps to the endpoint. Example: cn-hangzhou. This parameter is required if you use the signature algorithm V4.
region = "cn-hangzhou"

# Specify the name of the bucket.
bucket = oss2.Bucket(auth, endpoint, "examplebucket", region=region)

# Delete the server-side encryption configurations of the bucket. 
result = bucket.delete_bucket_encryption()
# Display the returned HTTP status code. 
print('http status:', result.status)

İlgili kaynaklar

  • Sunucu tarafı şifreleme için tam örnek kodu görüntülemek üzere GitHub adresini ziyaret edin.

  • Sunucu tarafı şifrelemeyi yapılandırmaya yönelik API işlemi hakkında daha fazla bilgi için bkz. PutBucketEncryption.

  • Sunucu tarafı şifreleme yapılandırmalarını sorgulamaya yönelik API işlemi hakkında daha fazla bilgi için bkz. GetBucketEncryption.

  • Sunucu tarafı şifreleme yapılandırmalarını silmeye yönelik API işlemi hakkında daha fazla bilgi için bkz. DeleteBucketEncryption.