各位大侠,我是新手,用BouncyCastle加载证书时报NullPointerException,以下是程序:
byte[] bDerCertBuf = new byte[MAX_CERT_BUF_LEN];
if(b64certBuf == null)
{
return null;
}
bDerCertBuf = Base64.decode(b64certBuf);
InputStream in = new ByteArrayInputStream(bDerCertBuf);
CertificateFactory cf = CertificateFactory.getInstance( "X.509 ", "BC ");
if(cf != null){
X509Certificate cert = (X509Certificate)cf.generateCertificate(in);
System.out.println(cert.toString()); //到这里cert为null
return cert; //返回cert后再用到它时就报NullPointerException了
}
else{
throw new IOException( " File " + cf.toString() + " is unreadable ");
}
急盼帮助一下下,不胜感激!
------解决方法--------------------------------------------------------
应该是base64的证书不合法,以前遇见过,忘了是带还是不带-----BEGIN CERTIFICATE-----那个头了,好像如果是带,就不要decode,直接b64certBuf.getByte()应该就可以了,如果不带就decode,这样才能成功。