我想通过对其应用加密将 blob 上传到 azure blob 存储中。所以我尝试使用以下代码来做到这一点:
File f=new File("/home/prospera-user15/Desktop/test/download.jpeg");
CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString);
CloudBlobClient serviceClient = account.createCloudBlobClient();
// Container name must be lower case.
CloudBlobContainer container = serviceClient.getContainerReference("upload1");
container.createIfNotExists();
CloudBlockBlob blob = container.getBlockBlobReference("megha");
final KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(2048);
final KeyPair wrapKey = keyGen.generateKeyPair();
RsaKey key = new RsaKey("RSA",wrapKey);
System.out.println("Uploading the encrypted blob.");
BlobEncryptionPolicy policy = new BlobEncryptionPolicy(key, null);
BlobRequestOptions options = new BlobRequestOptions();
options.setEncryptionPolicy(policy);
AccessCondition accessCondition = null;
OperationContext opContext = null;
try{
blob.upload(new FileInputStream(f), f.length(), accessCondition, options, opContext);
}catch (IOException e) {
System.out.println(e.getMessage());
}catch (StorageException e) {
System.out.println(e.getErrorCode());
}