I am having some problem with the following piece of code..
When I extracted the public key and saved to file, the Public key file looks
like:
-----BEGIN PUBLIC KEY-----
MIGdMA0GCSqGSIb3DQEBAQUAA4GLADCBhwKBgQCcKeojdze5WBip9ZT5GzNu6gcg
X/Vw4hftCDIQ5TQ6DHDxKxBfapCgKx/4tIgomsm3P9Q6JjhxOZjv/zOvlmQDtVb5
qnNnV8TxnA5n8LT7lrgKX2aiPVLmmaA2VnpAetL7shUUy46Tu+prSIIne3n80vRI
5vR7e5ghrRZAGSs2YQIBAw==
-----END PUBLIC KEY
The above Public key is not valid. It misses out ------ at the end.
I am not able to figure out what is problem.
Any suggestions/thoughts??
Thank you
Thanks Stephen and Dave....Thank you very much for your inputs..
X509 *x509;
int main()
{
x509 = NULL;
fp=fopen("RSAKey.cer","rb");
if(fp == NULL)
{
printf("Could not open the file \n");
return 0;
}
else
{
printf("Certificate file opened successfully \n");
}
x509 = PEM_read_X509(fp,NULL,NULL,NULL);
if(x509 == NULL)
{
printf("error reading \n");
}
else
{
printf("reading success\n");
ExtractSerialNumber();
ExtractPubKey();
}
fclose(fp);
X509_free(x509);
}
int ExtractSerialNumber()
{
ASN1_INTEGER *ptr;
int iIndex = 0;
printf("Entered func - ExtractSerialNumber\n");
ptr = X509_get_serialNumber(x509);
printf("\nThe length of the serial number is %d \n",ptr->length);
while(iIndex < (int)ptr->length )
{
sprintf(gszSerialNumber+iIndex*2, "%0.2X",ptr->data[iIndex++]);
}
printf("Serial Number is = %s\n", gszSerialNumber);
return 1;
}
int ExtractPubKey()
{
FILE *fp;
EVP_PKEY *PubKey;
int iRetVal = 0;
printf("Entered func - ExtractPubKey\n");
fp = fopen("RSAPubKey.Dat", "w+");
if(fp == NULL)
{
printf("Some problem with the file opening/creation \n");
return 0;
}
else
{
printf("File is opened \n");
}
PubKey = X509_get_pubkey(x509);
iRetVal = PEM_write_PUBKEY(fp, PubKey);
printf("The return value of PEM_write_PUBKEY is %d \n", iRetVal);
free(fp);
return iRetVal;
}
Thank you very much....
--
View this message in context:
http://old.nabble.com/Extract-of-Public-key-and-Serial-number-from-Certificate-tp33354749p33364574.html
Sent from the OpenSSL - User mailing list archive at Nabble.com.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [email protected]