(C) Get Public Key from Certificate PEM
Loads a certificate from a PEM file and gets the cert's public key.
#include <C_CkCert.h>
#include <C_CkPublicKey.h>
void ChilkatSample(void)
{
HCkCert cert;
BOOL success;
HCkPublicKey pubkey;
cert = CkCert_Create();
success = CkCert_LoadFromFile(cert,"qa_data/certs/someCert.pem");
if (success != TRUE) {
printf("%s\n",CkCert_lastErrorText(cert));
CkCert_Dispose(cert);
return;
}
// Get the certificate's public key:
pubkey = CkCert_ExportPublicKey(cert);
if (CkCert_getLastMethodSuccess(cert) != TRUE) {
printf("%s\n",CkCert_lastErrorText(cert));
CkCert_Dispose(cert);
return;
}
printf("%s\n",CkPublicKey_getPem(pubkey,FALSE));
// OK.. we have the public key which can be used in other Chilkat classes/methods...
CkPublicKey_Dispose(pubkey);
CkCert_Dispose(cert);
}
|