Archived Forum Post

Index of archived forum posts


Extract Public/Private Keys and Certs from PFX into variable strings

Mar 16 '13 at 13:44


i'm trying to test the "Extract Public/Private Keys and Certs from PFX into string variables" method in my program, but i keep getting these two errors at the statement fname = ERROR-CONCAT;, eventhough i didn't change any thing, except for adding my certificate's name and its password: The errors are: [bcc32 Error] ExtractPublicPrivateKeys.cpp(117): E2451 Undefined symbol 'ERROR'

[bcc32 Error] ExtractPublicPrivateKeys.cpp(117): E2451 Undefined symbol 'CONCAT'

void ChilkatSample(void) { bool success; CkCertStore certStore;

//  Load the PFX file into a certificate store object
CkString password;
password = "merchant1";
success = certStore.LoadPfxFile("Merchant.pfx",password);
if (success != true) {

int i;
int numCerts;
numCerts = certStore.get_NumCertificates();

//  Loop over each certificate in the PFX.
CkCert *cert = 0;
CkString fname;
for (i = 0; i <= numCerts - 1; i++) {

    cert = certStore.GetCertificate(i);


    CkString encodedCert;
    encodedCert = cert->getEncoded();

    //  This string may now be stored in a relational database string field.
    //  To re-create the cert, do this:
    CkCert cert2;

    //  Does this cert have a private key?
    if (cert->HasPrivateKey() == true) {

        //  Get the private key.
        CkPrivateKey *pvkey = 0;
        pvkey = cert->ExportPrivateKey();

        //  The private key can be exported into
        //  a string in PKCS8, RSA PEM, or XML format:
        CkString pemPvKey;
        CkString pkcs8PvKey;
        CkString xmlPvKey;

        pemPvKey = pvkey->getRsaPem();
        pkcs8PvKey = pvkey->getPkcs8Pem();
        xmlPvKey = pvkey->getXml();

        printf("%s\n",(const char *)pemPvKey);
        printf("%s\n",(const char *)pkcs8PvKey);
        printf("%s\n",(const char *)xmlPvKey);

        //  Any of these formatted strings may
        //  be stored in a relational database field.
        //  to restore, call LoadPem or LoadXml
        //  LoadPem accepts either RSA PEM or
        //  PKCS8 PEM:
        CkPrivateKey pvKey2;


        delete pvkey;


    //  Now for the public key:
    CkPublicKey *pubkey = 0;
    pubkey = cert->ExportPublicKey();

    //  It can be exported to a string as OpenSSL PEM
    //  or XML:
    CkString pubKeyPem;
    CkString pubKeyXml;

    pubKeyPem = pubkey->getOpenSslPem();
    pubKeyXml = pubkey->getXml();

    printf("%s\n",(const char *)pubKeyPem);
    printf("%s\n",(const char *)pubKeyXml);

    //  To re-load a PublicKey object, call LoadXml
    //  or LoadOpenSslPem:
    CkPublicKey pubKey2;

    fname = ERROR-CONCAT;

    delete pubkey;

    delete cert;

//  The Chilkat Certificate, Certificate Store, Private Key,
//  Public Key, and Key Container classes / objects are freeware.

//  They are used by and included with the Chilkat Email,
//  Crypt, S/MIME, and other commercial Chilkat components.


can you please help me! Regards


Looks like SaveOpenSslDerFile is expecting a file path as a parameter - I'm not sure what ERROR-CONCAT is supposed to be though.