Search code examples
javaazure-keyvaultprivate-keypkcs#12akv2k8s

How to access private key as PrivateKey object from a pfx certificate stored in Azure key vault using Java?


CertificateClient certificateClient = new CertificateClientBuilder().vaultUrl().credential(new DefaultAzureCredentialBuilder().build()).buildClient(); KeyVaultCertificateWithPolicy certificate = certificateClient.getCertificate("certificateName")


Solution

  • This is an example dealing with exactly the case you mentioned: https://github.com/nagyesta/lowkey-vault-example/blob/main/src/main/java/com/github/nagyesta/lowkeyvault/example/impl/AzureCertificateRepositoryImpl.java#L38-L59

    The example is dealing with an EC key, but you can simply cast it to the RSA specific class the same way.