title: Converting certificate byte[] to X509Certificate in Java
body: <p>I've stored a certificate as a Base64 encoded string in the database. I can read this  from the the database and decode it but I'd like to convert the decoded byte[] into a X509Certificate. I am looking for sample code to do this. I have tried:</p>
  
  <pre><code>CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
  InputStream in = new ByteArrayInputStream(bytes);
  X509Certificate cert = (X509Certificate)certFactory.generateCertificate(in);
  </code></pre>
  
  <p>This leads to an issue with the encoding type. A valid sample String or byte[] that represents a certificate will be good.</p>
  
  <p>Any pointers will be great! Thanks.</p>