title: How can I export X509Certificate in ASN1 format using bouncy castle in java?
body: <p>How can I export a <code>X509Certificate</code> in ASN.1 format?
  I found how to export to <strong>DER</strong> and <strong>PEM</strong>, using <code>.cer</code> extension, but I can not find how to export to ASN.1 format. Can anyone help me?</p>
  
  <p>This is my PEM:</p>
  
  <pre><code>JcaPEMWriter pemWrt = new JcaPEMWriter(new FileWriter(path + ".cer"))
  X509Certificate certificate = (X509Certificate) keyStore.getCertificate(loadCertificate);
  pemWrt.writeObject(certificate);
  pemWrt.flush();
  pemWrt.close();
  </code></pre>
  
  <p>This is my DER:</p>
  
  <pre><code>X509Certificate certificate = (X509Certificate) keyStore.getCertificate(loadCertificate);
  FileOutputStream fileWrite = new FileOutputStream(new File(path + ".cer"));
  fileWrite.write(certificate.getEncoded());
  fileWrite.flush();
  fileWrite.close();
  </code></pre>