[英]How to make sure your files are encrypted when using AWS S3 KMS encryption?
我正在嘗試使用 AWS S3 和 AWS java SDK(同時嘗試 v1 和 v2)測試有關加密/解密的最基本用例。
所以這就是我正在做的事情:
我使用 aws 控制台上傳了一個小的 json 文件,然后在“屬性”>“地穴”中檢查是否選擇了“AWS-KMS”並選擇了我的密鑰別名。 我假設這告訴我文件是用我的密鑰加密的,但我無法檢查這一點,因為如果我嘗試使用 aws 控制台打開文件,它是明文形式的。
我嘗試使用各種方法下載文件,我希望在使用最基本的方法時得到一個加密文件。
所以通過使用這個客戶端(sdk v2):
@Bean
public S3Client s3Clientv2(AppProperties appProperties, CustomAwsCredentialsProvider customAwsCredentialsProvider) {
return S3Client.builder()
.httpClientBuilder(httpClientBuilder)
.credentialsProvider(customAwsCredentialsProvider)
.region(Region.EU_WEST_3)
.build();
}
這個下載方法:
public void downloadFile(String bucket, String key) {
s3Client.getObject(GetObjectRequest.builder().bucket(bucket).key(key).build(), ResponseTransformer.toFile(Paths.get("test_aws.json")));
}
我希望得到一個加密文件,但事實並非如此。
然后我嘗試使用能夠自行“加密/解密”的客戶端“使用此客戶端從 Amazon S3 獲得的任何對象都會自動解密”來源: https://docs.aws.amazon.com/en_pv/sdk-for -java/v1/developer-guide/examples-crypto-kms.html
AmazonS3Encryption s3Encryption = AmazonS3EncryptionClientBuilder
.standard()
.withRegion(Regions.US_WEST_2)
.withCryptoConfiguration(new CryptoConfiguration(CryptoMode.EncryptionOnly).withAwsKmsRegion(Region.getRegion(Regions.US_WEST_2)))
// Can either be Key ID or alias (prefixed with 'alias/')
.withEncryptionMaterials(new KMSEncryptionMaterialsProvider("alias/s3-kms-key"))
.build();
但是使用:
S3Object file = s3Encryption.getObject(new GetObjectRequest(bucket, key));
使用此客戶端調用會收到警告:“無法檢測存儲桶 '%s' 中 object '%s' 的加密信息。返回 object 而不解密。”
更新:當然,我已經檢查了 object 元數據,其中確實包含 KMS 信息和 KMS 密鑰 ID,但加密客戶端期待有關此的一些其他信息:
/** Initialization vector (IV) header that is used in the symmetric and envelope encryption mechanisms */
public static final String CRYPTO_IV = "x-amz-iv";
和這個:
/**
* Encrypted symmetric key header that is used in the Encryption Only (EO) envelope
* encryption mechanism.
*/
public static final String CRYPTO_KEY = "x-amz-key";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.