hello ,
 
i have a problem using ssleay.
just now i have a certificate.
 
and i want to read the whole of data in X509 format.
 
i am using VC++ but still have error.
the code is
 
#include <stdio.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
       
main()
{
   X509 *x;
   FILE *fp;
   EVP_PKEY *      pkey;
   ASN1_INTEGER *serial;
 
   char * s;
   char * z;
 
   if ((fp=fopen("C:\\CryptoWeb\\492001fromhaizad\\Haizad.crt","r")) != NULL)
   {
      x=X509_new();
      if (PEM_read_X509(fp,&x,NULL,NULL)!=NULL)
         printf("\nReading success!\n");
   else
  
   {
    
 
   printf ("\nError reading certificate!");
   exit (1);
  }
  printf("\nCertificate value: %s",x);
     serial = X509_NAME_oneline(X509_get_serialNumber(x), NULL,NULL);
     printf("\nSerial Number:  %s\n",serial);
  // z = X509_NAME_oneline(X509_get_version(x), NULL,NULL);
    // printf("\nVersion:  %s\n",z);
  s = X509_NAME_oneline(X509_get_subject_name(x),NULL,NULL);
  printf("\nSUBJECT NAME:  %s\n",s);
  s = X509_NAME_oneline(X509_get_issuer_name(x),NULL,NULL);
  printf("\nISSUER NAME:  %s\n",s);
 
  /* Get public key - eay */
  pkey=X509_get_pubkey(x);
  if (pkey == NULL) {
   printf ("\nPublic key error!");
   exit (1);
  }
  
  if (pkey == NULL) {
    printf ("\nPublic key is NULL!");
   exit (1);
  }
  else
   printf ("Public key found!");
 
  printf("\nPublic key:");
  RSA_print_fp(stdout,pkey->pkey.rsa,0);
 
      X509_free(x);
      fclose(fp);
   }
   else
      perror("ERROR, haizad.crt");
 
}
can any body help me.
please reply as soon as posibble.

Reply via email to