Unicode C
Unicode C
ZATCA Load Certificate and Private Key from PEM Files
See more ZATCA Examples
Demonstrates how to load a certificate and private key from a pair of PEM files.Chilkat Unicode C Downloads
#include <C_CkCertW.h>
#include <C_CkPrivateKeyW.h>
void ChilkatSample(void)
{
BOOL success;
HCkCertW cert;
HCkPrivateKeyW privKey;
success = FALSE;
// The LoadFromFile method will automatically detect the file format..
cert = CkCertW_Create();
success = CkCertW_LoadFromFile(cert,L"qa_data/zatca/cert.pem");
if (success != TRUE) {
wprintf(L"%s\n",CkCertW_lastErrorText(cert));
CkCertW_Dispose(cert);
return;
}
wprintf(L"%s\n",CkCertW_subjectCN(cert));
// Load the private key.
privKey = CkPrivateKeyW_Create();
success = CkPrivateKeyW_LoadPemFile(privKey,L"qa_data/zatca/ec-secp256k1-priv-key.pem");
if (success != TRUE) {
wprintf(L"%s\n",CkPrivateKeyW_lastErrorText(privKey));
CkCertW_Dispose(cert);
CkPrivateKeyW_Dispose(privKey);
return;
}
wprintf(L"Key Type: %s\n",CkPrivateKeyW_keyType(privKey));
// Associate the private key with the certificate.
success = CkCertW_SetPrivateKey(cert,privKey);
if (success != TRUE) {
wprintf(L"%s\n",CkCertW_lastErrorText(cert));
CkCertW_Dispose(cert);
CkPrivateKeyW_Dispose(privKey);
return;
}
wprintf(L"Success.\n");
CkCertW_Dispose(cert);
CkPrivateKeyW_Dispose(privKey);
}