(C++) ZATCA Load Certificate and Private Key from PEM Files
Demonstrates how to load a certificate and private key from a pair of PEM files.
#include <CkCert.h>
#include <CkPrivateKey.h>
void ChilkatSample(void)
{
// The LoadFromFile method will automatically detect the file format..
CkCert cert;
bool success = cert.LoadFromFile("qa_data/zatca/cert.pem");
if (success != true) {
std::cout << cert.lastErrorText() << "\r\n";
return;
}
std::cout << cert.subjectCN() << "\r\n";
// Load the private key.
CkPrivateKey privKey;
success = privKey.LoadPemFile("qa_data/zatca/ec-secp256k1-priv-key.pem");
if (success != true) {
std::cout << privKey.lastErrorText() << "\r\n";
return;
}
std::cout << "Key Type: " << privKey.keyType() << "\r\n";
// Associate the private key with the certificate.
success = cert.SetPrivateKey(privKey);
if (success != true) {
std::cout << cert.lastErrorText() << "\r\n";
return;
}
std::cout << "Success." << "\r\n";
}
|