public static void s3WithEncryption(AWSCredentials credentials) {
String myKeyPair = "KEY_GENERATED_USING_ABOVE_CODE";
SecretKey mySymmetricKey = new SecretKeySpec(Base64.decodeBase64(myKeyPair.getBytes()), "AES");
EncryptionMaterials materials = new EncryptionMaterials(mySymmetricKey);
AmazonS3Client encryptedS3 = new AmazonS3EncryptionClient(credentials, materials);
try {
File file = new File("D:/dummy.txt");
SSECustomerKey sseKey = new SSECustomerKey(myKeyPair);
PutObjectRequest objectRequest = new PutObjectRequest(bucketName, "withEncrypt/dummy.txt", file);
encryptedS3.putObject(objectRequest.withSSECustomerKey(sseKey));
System.out.println("s3WithEncryption: Object uploaded!!!");
S3Object downloadedObject = encryptedS3.getObject(new GetObjectRequest(bucketName, "withEncrypt/" + file.getName()).withSSECustomerKey(sseKey));
downloadFile("D:/withEncrption", downloadedObject.getObjectContent(), "Steps to configure unifiedUI.txt");
System.out.println("s3WithEncryption: Object Downloaded!!!");
} catch (Exception e) {
e.printStackTrace();
} finally {
encryptedS3.shutdown();
}
}