Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

CertificateException: Unable to initialize

843810Sep 3 2003 — edited Sep 5 2003
Hello,

I am trying to programmatically access the content of a user certificate. I am able to successfully access certificates listed in an LDIF file using this code:

CertificateFactory cf = CertificateFactory.getInstance("X.509");
ByteArrayInputStream bais = new ByteArrayInputStream(certBytes);
idCert = (X509Certificate) cf.generateCertificate(bais);

where certBytes is the string representation of the certificate translated into byte form using the getBytes() method of the string class.

However, when I try to access the content of a certificate from a changerecord (which is supposed to have the same format as an LDIF file) using the same technique, I get these errors:

java.security.cert.CertificateException: Unable to initialize, java.io.IOException: insufficient data
at sun.security.x509.X509CertImpl.<init>(X509CertImpl.java:289)
at sun.security.provider.X509Factory.engineGenerateCertificate(X509Factory.java:94)
at java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:389)
at mil.disa.gds.util.CertificateAccess.init(CertificateAccess.java:33)
at mil.disa.gds.tempMeta.LiveUpdate.doModify(LiveUpdate.java:713)
at mil.disa.gds.tempMeta.LiveUpdate.processResults(LiveUpdate.java:475)
at mil.disa.gds.tempMeta.LiveUpdate.main(LiveUpdate.java:40)
Caused by: java.io.IOException: insufficient data
at sun.security.util.DerInputBuffer.truncate(DerInputBuffer.java:108)
at sun.security.util.DerValue.<init>(DerValue.java:249)
at sun.security.util.DerInputStream.getDerValue(DerInputStream.java:358)
at sun.security.x509.X509CertImpl.parse(X509CertImpl.java:1608)
at sun.security.x509.X509CertImpl.<init>(X509CertImpl.java:286)
... 6 more

When I print out the certificate contents to my application log and then extract the byte data to a .cer file, I can view the contents of the certificate (using Windows Explorer) so it seems like all the necessary pieces of data are there, but the generateCertificate method of the CertificateFactory class does not recognize the data as being a valid and complete certificate.

Any insight into this problem would be greatly appreciated.

vbj
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 3 2003
Added on Sep 3 2003
1 comment
3,015 views