Programming Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

C Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
DKIM / DomainKey
Diffie-Hellman
DSA
Email Object
Encryption
FileAccess
FTP
HTML Conversion
HTTP
IMAP
MHT / HTML Email
MIME
NTLM
POP3
RSA
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
Zip
Amazon S3

 

 

 

 

 

 

 

 

EDIFACT - S/MIME Create, Sign, and Encrypt

Create an EDIFACT MIME message, signs it, and then encrypts.

Downloads:

MS Windows Visual C/C++ Libraries
Linux/CentOS C/C++ Libraries
MAC OS X C/C++ Libraries
Solaris C/C++ Libraries
C++ Builder Libraries
#include <C_CkMime.h>
#include <C_CkCert.h>

void ChilkatSample(void)
    {
    HCkMime mime;
    BOOL success;
    const char * ediBody;
    HCkCert cert;
    HCkCert encryptCert;

    mime = CkMime_Create();

    success = CkMime_UnlockComponent(mime,"Anything for 30-day trial.");
    if (success == FALSE) {
        printf("%s\n",CkMime_lastErrorText(mime));
        return;
    }

    //  Assuming  you have an EDIFACT document loaded into
    //  a string variable, set the MIME body with it:

    ediBody = "UNB+IATB:1+6XPPC+LHPPC+940101:0950+1' ...";
    CkMime_SetBodyFromPlainText(mime,ediBody);

    //  The call to SetBodyFromPlainText automatically set the
    //  content-type to "text/plain".
    //  However, we want:  application/edifact;  name=om080923.edi
    CkMime_putContentType(mime,"application/edifact");
    CkMime_putName(mime,"om080923.edi");

    //  We want the content-disposition to be:
    //  Content-Disposition: attachment; filename="om080923.edi"
    CkMime_putDisposition(mime,"attachment");
    CkMime_putFilename(mime,"om080923.edi");

    //  Content-Transfer-Encoding: quoted-printable
    CkMime_putEncoding(mime,"quoted-printable");

    //  Note: MIME header fields are case insensitive.

    //  Add a few other header fields:
    CkMime_AddHeaderField(mime,"Message-ID","<CHILKAT-MID-83cf2fbf-10cb-4322-ad79-4c1097fd56f2@Matt>");
    CkMime_AddHeaderField(mime,"MIME-VERSION","1.0");

    //  Display the complete non-signed, non-encrypted MIME:
    printf("%s\n",CkMime_getMime(mime));
    printf("*********************************************\n");

    //  Sign the MIME using an opaque signature.
    //  (but first load a certificate)
    cert = CkCert_Create();
    success = CkCert_LoadByCommonName(cert,"Chilkat Software, Inc.");
    if (success == FALSE) {
        printf("%s\n",CkCert_lastErrorText(cert));
        return;
    }

    success = CkMime_ConvertToSigned(mime,cert);
    if (success == FALSE) {
        printf("%s\n",CkMime_lastErrorText(mime));
        return;
    }

    //  Perhaps the receiver is picky and wants the content-type to be "application/pkcs7-mime"
    //  instead of "application/x-pkcs7-mime".  In that case, simply set the content-type:
    CkMime_putContentType(mime,"applicaton/pkcs7-mime");

    //  Display the signed MIME:
    printf("%s\n",CkMime_getMime(mime));
    printf("*********************************************\n");

    //  Now encrypt it.
    encryptCert = CkCert_Create();
    success = CkCert_LoadByCommonName(encryptCert,"speedi speedi");
    if (success == FALSE) {
        printf("%s\n",CkCert_lastErrorText(encryptCert));
        return;
    }

    success = CkMime_Encrypt(mime,encryptCert);
    if (success == FALSE) {
        printf("%s\n",CkMime_lastErrorText(mime));
        return;
    }

    //  Again, if receiver is picky and wants the content-type to be "application/pkcs7-mime"
    //  instead of "application/x-pkcs7-mime".  In that case, simply set the content-type:
    CkMime_putContentType(mime,"applicaton/pkcs7-mime");

    //  Display the signed/encrypted MIME
    printf("%s\n",CkMime_getMime(mime));
    printf("*********************************************\n");

    //  Save the MIME to a file:
    success = CkMime_SaveMime(mime,"edifact_smime.txt");
    if (success == FALSE) {
        printf("%s\n",CkMime_lastErrorText(mime));
        return;
    }

    printf("Success!\n");

    CkMime_Dispose(mime);
    CkCert_Dispose(cert);
    CkCert_Dispose(encryptCert);

    }

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.