trying to do simple X509 certificate parsing (with a known good
certificate)
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());
}
when it gets to generateCertificate - it throws an exception --
12-10 18:24:00.297: ERROR/testapp(1471): exception:
org.apache.harmony.security.asn1.ASN1Exception: ASN.1 sequence
identifier is expected at [0], but encountered: 86
I verified my Base64InputStream class is producing the correct output,
and I know that the certificate is good. Is there something I need to
setup or something special I need to do to get this to work?
tia
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en