title: Reading an X.509 certificate with Java
body: <p>I am trying to use Java to read a certificate that I received from an external party. The code is throwing the following error:</p>
  
  <blockquote>
    <p>java.lang.RuntimeException: java.security.cert.CertificateException: Unable to initialize, java.io.IOException: extra data given to DerValue constructor</p>
  </blockquote>
  
  <p>The code:</p>
  
  <pre><code>FileInputStream ksfis = new FileInputStream(this.getCertificateFile());
  ksbufin = new BufferedInputStream(ksfis);
  certificate = (X509Certificate)
    CertificateFactory.getInstance("X.509").generateCertificate(ksbufin);
  </code></pre>
  
  <p>To make sure the problem was not in the code, I created a self-signed certificate and used it with the code, and it worked fine. I have installed both certificates in the system key chain, and they both are valid. I am using a Mac and Java 1.6.</p>
  
  <p>Any idea why I get the above exception when I load the external Party certificate? Do you think it got corrupted during transfer? If it did, it should not show up as valid on the local system, right?</p>