Source:
public static void main(String[] args) throws IOException, InterruptedException, IllegalArgumentException { CertificateClient certificateClient = new CertificateClientBuilder() .vaultUrl("https://{YOUR_VAULT_NAME}.vault.azure.net") .credential(new DefaultAzureCredentialBuilder().build()) .buildClient(); CertificatePolicy policy = new CertificatePolicy("Self", "CN=SelfSignedJavaPkcs12") .setSubjectAlternativeNames(new SubjectAlternativeNames().setEmails(Arrays.asList("wow@gmail.com"))) .setKeyReusable(true) .setKeyCurveName(CertificateKeyCurveName.P_256); Map<String, String> tags = new HashMap<>(); tags.put("foo", "bar"); SyncPoller<CertificateOperation, KeyVaultCertificate> certificatePoller = certificateClient.beginCreateCertificate("certificateName", policy, true, tags); certificatePoller.waitUntil(LongRunningOperationStatus.SUCCESSFULLY_COMPLETED); KeyVaultCertificate cert = certificatePoller.getFinalResult(); String backupFilePath = "YOUR_BACKUP_FILE_PATH"; byte[] certificateBackup = certificateClient.backupCertificate("certificateName"); System.out.printf("Backed up certificate with back up blob length %d", certificateBackup.length); writeBackupToFile(certificateBackup, backupFilePath); SyncPoller<DeletedCertificate, Void> deletedCertificatePoller = certificateClient.beginDeleteCertificate("certificateName"); PollResponse<DeletedCertificate> pollResponse = deletedCertificatePoller.poll(); System.out.printf("Deleted certitifcate with name %s and recovery id %s", pollResponse.getValue().getName(), pollResponse.getValue().getRecoveryId()); deletedCertificatePoller.waitForCompletion(); Thread.sleep(30000); certificateClient.purgeDeletedCertificateWithResponse("certificateName", new Context("key1", "value1")); Thread.sleep(15000); byte[] backupFromFile = Files.readAllBytes(new File(backupFilePath).toPath()); KeyVaultCertificate restoredCertificate = certificateClient.restoreCertificateBackup(backupFromFile); System.out.printf(" Restored certificate with name %s and id %s", restoredCertificate.getProperties().getName(), restoredCertificate.getProperties().getId()); }

Target:
public static void main(String[] args) throws IOException, InterruptedException, IllegalArgumentException { CertificateClient certificateClient = new CertificateClientBuilder() .vaultUrl("https://{YOUR_VAULT_NAME}.vault.azure.net") .credential(new DefaultAzureCredentialBuilder().build()) .buildClient(); CertificatePolicy policy = new CertificatePolicy("Self", "CN=SelfSignedJavaPkcs12") .setSubjectAlternativeNames(new SubjectAlternativeNames().setEmails(Arrays.asList("wow@gmail.com"))) .setKeyReusable(true) .setKeyCurveName(CertificateKeyCurveName.P_256); Map<String, String> tags = new HashMap<>(); tags.put("foo", "bar"); SyncPoller<CertificateOperation, KeyVaultCertificateWithPolicy> certificatePoller = certificateClient.beginCreateCertificate("certificateName", policy, true, tags); certificatePoller.waitUntil(LongRunningOperationStatus.SUCCESSFULLY_COMPLETED); KeyVaultCertificate cert = certificatePoller.getFinalResult(); String backupFilePath = "YOUR_BACKUP_FILE_PATH"; byte[] certificateBackup = certificateClient.backupCertificate("certificateName"); System.out.printf("Backed up certificate with back up blob length %d", certificateBackup.length); writeBackupToFile(certificateBackup, backupFilePath); SyncPoller<DeletedCertificate, Void> deletedCertificatePoller = certificateClient.beginDeleteCertificate("certificateName"); PollResponse<DeletedCertificate> pollResponse = deletedCertificatePoller.poll(); System.out.printf("Deleted certitifcate with name %s and recovery id %s", pollResponse.getValue().getName(), pollResponse.getValue().getRecoveryId()); deletedCertificatePoller.waitForCompletion(); Thread.sleep(30000); certificateClient.purgeDeletedCertificateWithResponse("certificateName", new Context("key1", "value1")); Thread.sleep(15000); byte[] backupFromFile = Files.readAllBytes(new File(backupFilePath).toPath()); KeyVaultCertificate restoredCertificate = certificateClient.restoreCertificateBackup(backupFromFile); System.out.printf(" Restored certificate with name %s and id %s", restoredCertificate.getProperties().getName(), restoredCertificate.getProperties().getId()); }