我的证书和CRL都在同一个PEM文件中,如下所示
-----END X509 CRL---------。
我想读取的数据如下
try
{
ByteArrayInputStream temp= new ByteArrayInputStream( cacert_file_data );
while(temp.available()>0 )
{
x509_cacert = (java.security.cert.X509Certificate)cf.generateCertificate(temp);
if (x509_cacert == null) { return ; } // paranoid
cert_list.add( x509_cacert );
}
}
catch (CertificateException e)
{some code}
在读取CRL时,它会抛出CertificateException,有什么办法可以避免这个异常,并从同一个文件中无异常地读取CRL。
ByteArrayInputStream bis= new ByteArrayInputStream( cacert_file_data );
int count = bis.available();
int pos = 0;
String cacert_str;
try
{
while(bis.available()>0 )
{
x509_cacert = (java.security.cert.X509Certificate)cf.generateCertificate(bis);
if (x509_cacert == null) { return ; } // paranoid
cert_list.add( x509_cacert );
pos = count - bis.available();
byte[] bytes = new byte[bis.available()];
bis.read(bytes, 0, bis.available());
bis.reset();
bis.skip(pos);
cacert_str = new String( bytes );
if(!cacert_str.contains("-----BEGIN CERTIFICATE-----"))
{
break;
}
}
}