title: How to programmatically extract information from certificate?
body: <p>I have a generated a certificate, but I would like to be able to extract the information from the certificate, as for example the country, the validity, the public key and so on. I have to compare this information retrived from the certificate with some other that I have stored in my C programe.  </p>
  
  <p>I know that if I use a function like this it will print me the certificate information:</p>
  
  <pre><code>void print_certificate(const char* cert)
  {
      X509 *x509 = NULL;
      BIO *i = BIO_new(BIO_s_file());
      BIO *o = BIO_new_fp(stdout,BIO_NOCLOSE);
  
      if((BIO_read_filename(i, cert) &lt;= 0) ||
         ((x509 = PEM_read_bio_X509_AUX(i, NULL, NULL, NULL)) == NULL)) {
             printf("Bad certificate, unable to read\n");
      }
  
      X509_print_ex(o, x509, XN_FLAG_COMPAT, X509_FLAG_COMPAT);   
  
      if(x509)
          X509_free(x509);
  }
  </code></pre>
  
  <p>But what I want is only some parts of that information. how can it be done?</p>
  
  <p>Thanks</p>