(Unicode C) Get Public Key from Certificate PEM
Loads a certificate from a PEM file and gets the cert's public key.
#include <C_CkCertW.h>
#include <C_CkPublicKeyW.h>
void ChilkatSample(void)
{
HCkCertW cert;
BOOL success;
HCkPublicKeyW pubkey;
cert = CkCertW_Create();
success = CkCertW_LoadFromFile(cert,L"qa_data/certs/someCert.pem");
if (success != TRUE) {
wprintf(L"%s\n",CkCertW_lastErrorText(cert));
CkCertW_Dispose(cert);
return;
}
// Get the certificate's public key:
pubkey = CkCertW_ExportPublicKey(cert);
if (CkCertW_getLastMethodSuccess(cert) != TRUE) {
wprintf(L"%s\n",CkCertW_lastErrorText(cert));
CkCertW_Dispose(cert);
return;
}
wprintf(L"%s\n",CkPublicKeyW_getPem(pubkey,FALSE));
// OK.. we have the public key which can be used in other Chilkat classes/methods...
CkPublicKeyW_Dispose(pubkey);
CkCertW_Dispose(cert);
}
|