hello.
i have a
problem how to read version and serial number from certificate.
just now i
have a certificate.
the code
like this
#include
<stdio.h>
#include <openssl/x509.h>
#include
<openssl/pem.h>
main()
{
X509
*x;
FILE *fp;
EVP_PKEY
* pkey;
long
version;
char * s;
if
((fp=fopen("C:\\CryptoWeb\\backup 492001\\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);
version =
X509_NAME_oneline(X509_get_version(x), NULL,NULL);
printf ("\nVersion: %s\n",version);
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");
}
this code
have some error.
can you
help me give any example.
please
reply as soon as possible.
thank
you