login about faq

Hi..

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) {
    printf("%s\n",certStore.lastErrorText());
    return;
}

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);

    printf("%s\n",cert->subjectDN());
    printf("---\n");

    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;
    cert2.SetFromEncoded(encodedCert);

    //  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;

        pvKey2.LoadPem(pemPvKey);
        pvKey2.LoadPem(pkcs8PvKey);
        pvKey2.LoadXml(xmlPvKey);

        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;

    pubKey2.LoadOpenSslPem(pubKeyPem);
    pubKey2.LoadXml(pubKeyXml);
    fname = ERROR-CONCAT;
    pubkey->SaveOpenSslDerFile(fname);

    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

asked Mar 16 '13 at 06:58

rania's gravatar image

rania
45182228


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

link

answered Mar 16 '13 at 13:44

jpbro's gravatar image

jpbro ♦
1.1k2618

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×26

Asked: Mar 16 '13 at 06:58

Seen: 1,217 times

Last updated: Mar 16 '13 at 13:44

powered by OSQA