How to read public key from PFX file in java

Posted by articlestack on Stack Overflow See other posts from Stack Overflow or by articlestack
Published on 2010-12-22T11:38:53Z Indexed on 2010/12/22 11:53 UTC
Read the original article Hit count: 431

I am able to read private key from PFX file but not public key. I am using following code to read public key.

InputStream inStream = new FileInputStream(certFile); 
CertificateFactory cf = CertificateFactory.getInstance("X.509"); 
BufferedInputStream bis = new BufferedInputStream(inStream);
// if (bis.available() > 0) {
java.security.cert.Certificate cert = cf.generateCertificate(bis);
System.out.println("This part is not getting printed in case of PFX file");
// }
puk = (PublicKey) cert.getPublicKey();

This code is working properly when i read from .cer file. Please help

© Stack Overflow or respective owner

Related posts about java

Related posts about publickey