Hi @Jeet Jangir ,
Thanks for reaching out.
Azure Key Vault provides a REST API and SDKs for various programming languages to interact with it.
You need to obtain the certificate from the Azure Key Vault using the Azure Key Vault SDK.
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.security.keyvault.certificates.CertificateClient;
import com.azure.security.keyvault.certificates.models.Certificate;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
// Initialize the certificate client with the DefaultAzureCredentialBuilder
CertificateClient certificateClient = new CertificateClientBuilder()
.vaultUrl("https://{YOUR_VAULT_NAME}.vault.azure.net/") // Replace with your Azure Key Vault URL
.credential(new DefaultAzureCredentialBuilder().build())
.buildClient();
// Specify the name of the certificate in the Azure Key Vault
String certificateName = "XYZ";
// Retrieve the certificate from the Azure Key Vault
Certificate certificate = certificateClient.getCertificate(certificateName);
// Save the certificate data to a temporary file (you can modify this path to your requirement)
File tempFile = File.createTempFile("temp-certificate", ".pfx");
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
fos.write(certificate.getCer());
}
// Now you can use tempFile.getAbsolutePath() as the path to the certificate file in your existing code.
File f = new File(tempFile.getAbsolutePath());
// Your existing code that uses the certificate file (f) can remain unchanged.
// ...
}
}
Hope this will help.
Thanks,
Shweta
Please remember to "Accept Answer" if answer helped you.