I am developing a code where I need to upload the file data into azure storage blob. My requirement is to upload this data in encrypted format,thus I am using azure key vault.
final String storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=abc;AccountKey=pqr+lov==";
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
com.microsoft.azure.storage.blob.CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
CloudBlobContainer container = blobClient.getContainerReference("plmcontainer2");
container.createIfNotExists();
String filePath = "C:\\STSWorkspace\\PLMSubscriberMS\\Payload.xml";
com.microsoft.azure.storage.blob.CloudBlockBlob blob = container.getBlockBlobReference("Payload4.xml");
java.io.File source = new java.io.File(filePath);
java.io.FileInputStream fileInputStream=new java.io.FileInputStream(source);
// blob.upload(fileInputStream, source.length());
//encryption code
// Create the IKey used for encryption.
RsaKey key = new RsaKey("private:key1" /* key identifier */);
// Create the encryption policy to be used for upload and download.
BlobEncryptionPolicy policy = new BlobEncryptionPolicy(key, null);
// Set the encryption policy on the request options.
BlobRequestOptions options = new BlobRequestOptions();
options.setEncryptionPolicy(policy);
AccessCondition accessCondition = null;
operationContext opContext = null;
// Upload the encrypted contents to the blob.
blob.upload(fileInputStream, source.length(), null, options, null); //here is exception
On the last line I am getting an exception,
if I change it to blob.upload(fileInputStream, source.length());
then the data is uploaded into blog but in plain text.
how do I use blob.upload(fileInputStream, source.length(), null, options, null);
what should I place at the location of null.
Exception
Exception in thread "main" com.microsoft.azure.storage.StorageException: A Client side exception occurred, please check the inner exception for details
at com.microsoft.azure.storage.StorageException.translateClientException(StorageException.java:42)
at com.microsoft.azure.storage.blob.BlobEncryptionPolicy.createAndSetEncryptionContext(BlobEncryptionPolicy.java:305)
at com.microsoft.azure.storage.blob.CloudBlockBlob.openOutputStream(CloudBlockBlob.java:575)
at com.microsoft.azure.storage.blob.CloudBlockBlob.upload(CloudBlockBlob.java:715)
at com.encrypt.blob.BlobEncryption.main(BlobEncryption.java:55)
Caused by: java.security.InvalidKeyException: Illegal key size or default parameters
at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1026)
at javax.crypto.Cipher.implInit(Cipher.java:801)
at javax.crypto.Cipher.chooseProvider(Cipher.java:864)
at javax.crypto.Cipher.init(Cipher.java:1249)
at javax.crypto.Cipher.init(Cipher.java:1186)
at com.microsoft.azure.storage.blob.BlobEncryptionPolicy.createAndSetEncryptionContext(BlobEncryptionPolicy.java:288)
... 3 more