AWS KMS 관리형 키를 사용한 Amazon S3 클라이언트 측 암호화 - AWS SDK for Java 1.x

곧 출시될 end-of-support AWS SDK for Java (v1) 버전을 발표했습니다. AWS SDK for Java V2로 마이그레이션하실 것을 권장합니다. 마이그레이션 날짜, 추가 세부 정보 및 방법에 대한 자세한 내용은 링크된 공지 사항을 참조하세요.

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

AWS KMS 관리형 키를 사용한 Amazon S3 클라이언트 측 암호화

다음 예제에서는 AmazonS3EncryptionClientV2Builder 클래스를 사용하여 클라이언트 측 암호화가 활성화된 Amazon S3 클라이언트를 만듭니다. 이렇게 구성하면 이 클라이언트로 Amazon S3에 업로드하는 모든 객체가 암호화됩니다. 또한 이 클라이언트를 사용하여 Amazon S3에서 가져오는 모든 객체는 자동으로 해독됩니다.

참고

다음 예제에서는 AWS KMS 관리형 키로 Amazon S3 클라이언트 측 암호화를 사용하는 방법을 보여 줍니다. 고객 자체 키로 암호화를 사용하는 방법은 클라이언트 마스터 키로 Amazon S3 클라이언트 측 암호화를 참조하십시오.

클라이언트 측 Amazon S3 암호화를 활성화할 때는 엄격히 인증된 암호화 또는 암호화 등 두 가지 암호화 모드 중에서 선택할 수 있습니다. 다음 단원에서는 각각의 유형을 활성화하는 방법에 대해 설명합니다. 각 모드에서 사용하는 알고리즘은 CryptoMode 정의를 참조하십시오.

필수적 가져오기

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

가져오기

import com.amazonaws.ClientConfiguration; import com.amazonaws.regions.Regions; import com.amazonaws.services.kms.AWSKMS; import com.amazonaws.services.kms.AWSKMSClientBuilder; import com.amazonaws.services.kms.model.GenerateDataKeyRequest; import com.amazonaws.services.kms.model.GenerateDataKeyResult; 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.KMSEncryptionMaterialsProvider;

엄격히 인증된 암호화

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

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

참고

클라이언트 측 인증된 암호화를 사용하려면 애플리케이션의 클래스 경로에 최신 Bouncy Castle jar 파일을 포함시켜야 합니다.

코드

AmazonS3EncryptionV2 s3Encryption = AmazonS3EncryptionClientV2Builder.standard() .withRegion(Regions.US_WEST_2) .withCryptoConfiguration(new CryptoConfigurationV2().withCryptoMode((CryptoMode.StrictAuthenticatedEncryption))) .withEncryptionMaterialsProvider(new KMSEncryptionMaterialsProvider(keyId)) .build(); s3Encryption.putObject(bucket_name, ENCRYPTED_KEY3, "This is the 3rd content to encrypt with a key created in the {console}"); System.out.println(s3Encryption.getObjectAsString(bucket_name, ENCRYPTED_KEY3));

Amazon S3 암호화 클라이언트에서 putObject 메서드를 호출하여 객체를 업로드합니다.

코드

s3Encryption.putObject(bucket_name, ENCRYPTED_KEY3, "This is the 3rd content to encrypt with a key created in the {console}");

같은 클라이언트를 사용하여 객체를 검색할 수 있습니다. 이 예제에서는 getObjectAsString 메서드를 호출하여 저장된 문자열을 검색합니다.

코드

System.out.println(s3Encryption.getObjectAsString(bucket_name, ENCRYPTED_KEY3));

인증된 암호화 모드

AuthenticatedEncryption 모드를 사용하여 암호화하면 향상된 키 래핑 알고리즘이 적용됩니다. 이 모드에서 암호를 해독할 때는 이 알고리즘이 해독된 객체의 무결성을 확인하고, 확인에 실패하면 예외가 발생합니다. 인증된 암호화의 작동 방식에 대한 자세한 내용은 Amazon S3클라이언트 측 인증된 암호화 블로그 게시물을 참조하십시오.

참고

클라이언트 측 인증된 암호화를 사용하려면 애플리케이션의 클래스 경로에 최신 Bouncy Castle jar 파일을 포함시켜야 합니다.

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

코드

AmazonS3EncryptionV2 s3Encryption = AmazonS3EncryptionClientV2Builder.standard() .withRegion(Regions.US_WEST_2) .withCryptoConfiguration(new CryptoConfigurationV2().withCryptoMode((CryptoMode.AuthenticatedEncryption))) .withEncryptionMaterialsProvider(new KMSEncryptionMaterialsProvider(keyId)) .build();

AWS KMS 클라이언트 구성

Amazon S3 암호화 클라이언트는 명시적으로 지정하지 않는 한 기본적으로 AWS KMS 클라이언트를 만듭니다.

자동으로 생성되는 AWS KMS 클라이언트의 지역을 설정하려면 awsKmsRegion를 설정합니다.

코드

Region kmsRegion = Region.getRegion(Regions.AP_NORTHEAST_1); AmazonS3EncryptionV2 s3Encryption = AmazonS3EncryptionClientV2Builder.standard() .withRegion(Regions.US_WEST_2) .withCryptoConfiguration(new CryptoConfigurationV2().withAwsKmsRegion(kmsRegion)) .withEncryptionMaterialsProvider(new KMSEncryptionMaterialsProvider(keyId)) .build();

또는 고유한 AWS KMS 클라이언트를 사용하여 암호화 클라이언트를 초기화할 수 있습니다.

코드

AWSKMS kmsClient = AWSKMSClientBuilder.standard() .withRegion(Regions.US_WEST_2); .build(); AmazonS3EncryptionV2 s3Encryption = AmazonS3EncryptionClientV2Builder.standard() .withRegion(Regions.US_WEST_2) .withKmsClient(kmsClient) .withCryptoConfiguration(new CryptoConfigurationV2().withCryptoMode((CryptoMode.AuthenticatedEncryption))) .withEncryptionMaterialsProvider(new KMSEncryptionMaterialsProvider(keyId)) .build();