

 AWS SDK for Java 1.x는 2025년 12월 31일에 end-of-support되었습니다. 새로운 기능, 가용성 개선 및 보안 업데이트를 계속 받으려면 [AWS SDK for Java 2.x](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/home.html)로 마이그레이션하는 것이 좋습니다.

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 클라이언트 마스터 키를 사용한 Amazon S3 클라이언트 측 암호화
<a name="examples-crypto-masterkey"></a>

다음 예제에서는 [AmazonS3EncryptionClientV2Builder](https://docs.aws.amazon.com/sdk-for-java/v1/reference/com/amazonaws/services/s3/AmazonS3EncryptionClientV2Builder.html) 클래스를 사용하여 클라이언트 측 암호화가 활성화된 Amazon S3 클라이언트를 만듭니다. 이렇게 설정하면 이 클라이언트로 Amazon S3에 업로드하는 모든 객체가 암호화됩니다. 또한 이 클라이언트를 사용하여 Amazon S3에서 가져오는 모든 객체는 자동으로 암호 해독됩니다.

**참고**  
다음 예제에서는 고객 관리형 클라이언트 마스터 키로 Amazon S3 클라이언트 측 암호화를 사용하는 방법을 보여 줍니다. AWS KMS 관리형 키로 암호화를 사용하는 방법은 [AWS KMS 관리형 키를 사용한 Amazon S3 클라이언트 측 암호화](examples-crypto-kms.md)를 참조하세요.

클라이언트 측 Amazon S3 암호화를 활성화할 때는 엄격히 인증된 암호화 또는 암호화 등 두 가지 암호화 모드 중에서 선택할 수 있습니다. 다음 단원에서는 각각의 유형을 활성화하는 방법에 대해 설명합니다. 각 모드에서 사용하는 알고리즘은 [CryptoMode](https://docs.aws.amazon.com/sdk-for-java/v1/reference/com/amazonaws/services/s3/model/CryptoMode.html) 정의를 참조하십시오.

## 필수 가져오기
<a name="required-imports"></a>

이 예제에 사용할 다음 클래스를 가져옵니다.

 **가져옵니다**.

```
import com.amazonaws.ClientConfiguration;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3EncryptionClientV2Builder;
import com.amazonaws.services.s3.AmazonS3EncryptionV2;
import com.amazonaws.services.s3.model.CryptoConfigurationV2;
import com.amazonaws.services.s3.model.CryptoMode;
import com.amazonaws.services.s3.model.EncryptionMaterials;
import com.amazonaws.services.s3.model.StaticEncryptionMaterialsProvider;
```

## 엄격히 인증된 암호화
<a name="strict-authenticated-encryption"></a>

어떠한 `CryptoMode`도 지정되지 않은 경우 엄격한 인증 암호화가 기본 모드입니다.

이 명시적으로 모드를 활성화하려면 `withCryptoConfiguration` 메서드에 `StrictAuthenticatedEncryption` 값을 지정합니다.

**참고**  
클라이언트 측 인증된 암호화를 사용하려면 애플리케이션의 클래스 경로에 최신 [Bouncy Castle jar](https://www.bouncycastle.org/download/bouncy-castle-java/) 파일을 포함시켜야 합니다.

 ** 코드** 

```
AmazonS3EncryptionV2 s3Encryption = AmazonS3EncryptionClientV2Builder.standard()
         .withRegion(Regions.US_WEST_2)
         .withCryptoConfiguration(new CryptoConfigurationV2().withCryptoMode((CryptoMode.StrictAuthenticatedEncryption)))
         .withEncryptionMaterialsProvider(new StaticEncryptionMaterialsProvider(new EncryptionMaterials(secretKey)))
         .build();

s3Encryption.putObject(bucket_name, ENCRYPTED_KEY2, "This is the 2nd content to encrypt");
```

## 인증된 암호화 모드
<a name="authenticated-encryption-mode"></a>

`AuthenticatedEncryption` 모드를 사용하여 암호화하면 향상된 키 래핑 알고리즘이 적용됩니다. 이 모드에서 암호를 해독할 때는 이 알고리즘이 해독된 객체의 무결성을 확인하고, 확인에 실패하면 예외가 발생합니다. 인증된 암호화의 작동 방식에 대한 자세한 내용은 [Amazon S3클라이언트 측 인증된 암호화](https://aws.amazon.com/blogs/developer/amazon-s3-client-side-authenticated-encryption) 블로그 게시물을 참조하세요.

**참고**  
클라이언트 측 인증된 암호화를 사용하려면 애플리케이션의 클래스 경로에 최신 [Bouncy Castle jar](https://www.bouncycastle.org/download/bouncy-castle-java/) 파일을 포함시켜야 합니다.

이 모드를 활성화하려면 `AuthenticatedEncryption` 메서드에 `withCryptoConfiguration` 값을 지정합니다.

 ** 코드** 

```
AmazonS3EncryptionV2 s3EncryptionClientV2 = AmazonS3EncryptionClientV2Builder.standard()
         .withRegion(Regions.DEFAULT_REGION)
         .withClientConfiguration(new ClientConfiguration())
         .withCryptoConfiguration(new CryptoConfigurationV2().withCryptoMode(CryptoMode.AuthenticatedEncryption))
         .withEncryptionMaterialsProvider(new StaticEncryptionMaterialsProvider(new EncryptionMaterials(secretKey)))
         .build();

s3EncryptionClientV2.putObject(bucket_name, ENCRYPTED_KEY1, "This is the 1st content to encrypt");
```