Description
Query/Question
How to fetch the private key from Azure Keyvault Secret and convert it to a "java.security.PrivateKey" Java object? I've tried a sample code as follows, but, it was throwing an exception. Could you please help?
KeyVaultSecret secret = secretClient.getSecret(name, version);
KeyFactory kf = KeyFactory.getInstance("RSA");
PrivateKey privateKey = kf.generatePrivate(new PKCS8EncodedKeySpec(Base64.getDecoder().decode(secret.getValue())));
It threw
Caused by: java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: unknown version: 3
at java.base/sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:253)
at java.base/java.security.KeyFactory.generatePrivate(KeyFactory.java:389)
Why is this not a Bug or a feature Request?
I just want to understand how to convert the private key value from the Keyvault secret to a "java.security.PrivateKey" Java object. It's not a bug or a feature request.
Setup (please complete the following information if applicable):
I'm using
- Azure Keyvault SDK (v 1.2.22) to fetch the secret.
- Java 17
Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- [y] Query Added
- [y] Setup information Added
Metadata
Metadata
Assignees
Labels
Type
Projects
Status