Is it possible to read the RSA private key of format PKCS1 in JAVA without converting to PKCS8? if yes, sample code is appreciated.
-----BEGIN RSA PRIVATE KEY-----
BASE64 ENCODED DATA
-----END RSA PRIVATE KEY-----
Java does not come with out-of-the-box support for PKCS1 keys. You can however use Bouncycastle
PEMParser pemParser = new PEMParser(new FileReader(privateKeyFile));
JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider("BC");
Object object = pemParser.readObject();
KeyPair kp = converter.getKeyPair((PEMKeyPair) object);
PrivateKey privateKey = kp.getPrivate();
java.security.NoSuchProviderException: no such provider: BC
Dec 5, 2018 at 15:54
Security.addProvider(new BouncyCastleProvider());
Dec 5, 2018 at 16:22
PEMParser
and JcaPEMKeyConverter
.... I tried using https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on/1.55
... but didn't work .... Which Jar I need to use or which grade do I need to use for this ?
bcpkix
and bcprov
. Try with compile "org.bouncycastle:bcprov-jdk15on:$bouncycastleVersion" compile "org.bouncycastle:bcpkix-jdk15on:$bouncycastleVersion"