(Unicode C) Get Certificate's Public Key
Loads a certificate from PEM and gets the public key.
#include <C_CkCertW.h>
#include <C_CkPublicKeyW.h>
void ChilkatSample(void)
{
HCkCertW cert;
const wchar_t *strPem;
BOOL success;
HCkPublicKeyW pubKey;
cert = CkCertW_Create();
strPem = L"-----BEGIN CERTIFICATE----- ...";
success = CkCertW_LoadPem(cert,strPem);
if (success != TRUE) {
wprintf(L"%s\n",CkCertW_lastErrorText(cert));
CkCertW_Dispose(cert);
return;
}
pubKey = CkCertW_ExportPublicKey(cert);
if (CkCertW_getLastMethodSuccess(cert) == FALSE) {
wprintf(L"%s\n",CkCertW_lastErrorText(cert));
CkCertW_Dispose(cert);
return;
}
// You can now use the public key object however it is needed,
// and access its various properties and methods..
wprintf(L"%s\n",CkPublicKeyW_getXml(pubKey));
CkPublicKeyW_Dispose(pubKey);
CkCertW_Dispose(cert);
}
|