I am using Amazon aws Java SDK for coding.
I have uploaded few of my local files to S3 by using SSE-C(server side encryption using customer provided key) and few files without using any encryption. Before downloading a file in some other module, I need to make sure whether that particular file is encrypted or not. I have referred this link. But this procedure is for files encrypted with SSE (which is different to SSE-C). After referring to Amazon aws Java APIs I have written below code.
Base64 b = new Base64();
byte[] keyBytes = b.decode("encryptionKey");
SecretKey key = new SecretKeySpec(keyBytes,0,keyBytes.length,"AES");
SSECustomerKey sseKey = new SSECustomerKey(key);
GetObjectMetadataRequest request2 =new GetObjectMetadataRequest("bucketname","keyname").withSSECustomerKey(sseKey);
ObjectMetadata metadata = s3client.getObjectMetadata(request2);
System.out.println("Encryption algorithm used: " + metadata.getSSECustomerAlgorithm());
The above piece of code is working fine to download an encrypted file. But giving exception while downloading file which was not encrypted.
Is there any common API to get the metadata of both encrypted and non encrypted files.
.withSSECustomerKey(sseKey)part? - augurar