我想知道在这个例子中我是否遗漏了一些代码。我在这个类中的 certHeader,certFooter 上遇到编译时错误。如果有人可以给我一个简短的想法,这将是有帮助的。或者如果有人有证书解析器的更好示例将有所帮助。我正在使用此示例来解析证书。
try
{
String abc = "-----BEGIN CERTIFICATE-----\n" + "ALneIwerZ5Nu+z1Yjvdco9sOHfkhYW4nL+FIlGDGIS +YsyevB8YN2hBnog7gtQ6PB+sVF6o/1UdU\n" + // lines deleted for brevity "rchFUEChHZ5G7AAk02K7/iyqITc/IPNHHpilTg/NB6QhF9s=\n" + "-----END CERTIFICATE-----";
int headerIndex = abc.indexOf(certHeader);
if (headerIndex == -1)
{
throw new CertificateParsingException("cannot find BEGIN CERTIFICATE");
}
int startIndex = headerIndex + certHeader.length();
int endIndex = abc.indexOf(certFooter);
if (endIndex == -1)
{
throw new CertificateParsingException("cannot find END CERTIFICATE"); }
String cert = abc.substring(startIndex, endIndex);
byte[] certBytes = cert.getBytes();
InputStream in = new Base64InputStream(new ByteArrayInputStream(certBytes));
CertificateFactory certFact = CertificateFactory.getInstance ("X.509");
Certificate certGen = certFact.generateCertificate(in);
X509Certificate x509 = (X509Certificate)
certGen;
}
catch (Exception e)
{
Log.e("testapp", "exception: " + e.getMessage());
}