大家好,又见面了,我是你们的朋友全栈君。
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
解决方案
Use the KeyStore class and treat the file as a PKCS#12 KeyStore. Use KeyStore.getInstance(“PKCS12”) to get an instance of a PKCS12 keystore.
The Javadocs for KeyStore contain sample code.
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/133194.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...