title: Having trouble converting a X509 Certificate to Base64
body: <p>I have a <code>X509 Certificate</code> and I want to store it in a <code>MySQL DB</code> instead of saving the file. Therefore, I thought it is better to convert the certificate to <code>base64</code> and store it. I have done the forward and reverse of this conversion however, I did not get true results.</p>
  
  <p>I'm using <code>javax.security.cert.X509Certificate</code> and import <code>org.apache.commons.codec.binary.Base64</code> as follows:</p>
  
  <pre><code>X509Certificate cert = X509Certificate.getInstance(new FileInputStream(certFile));
  System.out.println("Vigencia: "+cert.getNotAfter());
  System.out.println("Inicio: "+cert.getNotBefore());
  String cert64 = bytes2String(Base64.encodeBase64(cert.toString().getBytes("UTF-8")));
  System.out.println("Cert 64: "+ cert64);
  String certRegreso = bytes2String(Base64.decodeBase64(cert64.getBytes()));
  System.out.println("Cert Regreso: "+ certRegreso);
  X509Certificate certNuevo = X509Certificate.getInstance(certRegreso.getBytes());
  </code></pre>