

# Usar `GetBucketEncryption` com o AWS SDK ou a CLI
<a name="s3_example_s3_GetBucketEncryption_section"></a>

Os exemplos de código a seguir mostram como usar `GetBucketEncryption`.

------
#### [ .NET ]

**SDK para .NET**  
 Há mais no GitHub. Encontre o exemplo completo e saiba como configurar e executar no [AWSCode Examples Repository](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/dotnetv3/S3/PutBucketEncryption#code-examples). 

```
    /// <summary>
    /// Get and print the encryption settings of a bucket.
    /// </summary>
    /// <param name="bucketName">Name of the bucket.</param>
    /// <returns>Async task.</returns>
    public static async Task GetEncryptionSettings(string bucketName)
    {
        // Check and print the bucket encryption settings.
        Console.WriteLine($"Getting encryption settings for bucket {bucketName}.");

        try
        {
            var settings =
                await _s3Client.GetBucketEncryptionAsync(
                    new GetBucketEncryptionRequest() { BucketName = bucketName });

            foreach (var encryptionSettings in settings?.ServerSideEncryptionConfiguration?.ServerSideEncryptionRules!)
            {
                Console.WriteLine(
                    $"\tAlgorithm: {encryptionSettings.ServerSideEncryptionByDefault.ServerSideEncryptionAlgorithm}");
                Console.WriteLine(
                    $"\tKey: {encryptionSettings.ServerSideEncryptionByDefault.ServerSideEncryptionKeyManagementServiceKeyId}");
            }
        }
        catch (AmazonS3Exception ex)
        {
            Console.WriteLine(ex.ErrorCode == "InvalidBucketName"
                ? $"Bucket {bucketName} was not found."
                : $"Unable to get bucket encryption for bucket {bucketName}, {ex.Message}");
        }
    }
```
+  Para ter detalhes da API, consulte [GetBucketEncryption](https://docs.aws.amazon.com/goto/DotNetSDKV3/s3-2006-03-01/GetBucketEncryption) na *Referência da API do AWS SDK para .NET*. 

------
#### [ CLI ]

**AWS CLI**  
**Para recuperar a configuração de criptografia do lado do servidor para um bucket**  
O exemplo `get-bucket-encryption` a seguir recupera a configuração de criptografia do lado do servidor do bucket `amzn-s3-demo-bucket`.  

```
aws s3api get-bucket-encryption \
    --bucket {{amzn-s3-demo-bucket}}
```
Resultado:  

```
{
    "ServerSideEncryptionConfiguration": {
        "Rules": [
            {
                "ApplyServerSideEncryptionByDefault": {
                    "SSEAlgorithm": "AES256"
                }
            }
        ]
    }
}
```
+  Consulte detalhes da API em [GetBucketEncryption](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/get-bucket-encryption.html) na *Referência de comandos da AWS CLI*. 

------
#### [ PowerShell ]

**Ferramentas para PowerShell V4**  
**Exemplo 1: este comando retorna todas as regras de criptografia do lado do servidor associadas ao bucket em questão.**  

```
Get-S3BucketEncryption -BucketName 'amzn-s3-demo-bucket'
```
+  Consulte detalhes da API em [GetBucketEncryption](https://docs.aws.amazon.com/powershell/v4/reference) na *Referência de cmdlet do Ferramentas da AWS para PowerShell (V4)*. 

**Ferramentas para PowerShell V5**  
**Exemplo 1: este comando retorna todas as regras de criptografia do lado do servidor associadas ao bucket em questão.**  

```
Get-S3BucketEncryption -BucketName 'amzn-s3-demo-bucket'
```
+  Consulte detalhes da API em [GetBucketEncryption](https://docs.aws.amazon.com/powershell/v5/reference) na *Referência de cmdlet do Ferramentas da AWS para PowerShell (V5)*. 

------

Para ver uma lista completa dos guias de desenvolvedor e exemplos de código do SDK da AWS, consulte [Desenvolvimento com o Amazon S3 usando AWS SDKs](sdk-general-information-section.md). Este tópico também inclui informações sobre como começar e detalhes sobre versões anteriores do SDK.