Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
EDIFACT - S/MIME Create, Sign, and EncryptCreate 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 FreeBSD C++ Libraries HP-UX C++ Libraries BlackBerry QNX C++ Libraries // Needs #include <CkMime.h> // Needs #include <CkCert.h> CkString strOut; CkMime mime; bool success; success = mime.UnlockComponent("Anything for 30-day trial."); if (success == false) { strOut.append(mime.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } // Assuming you have an EDIFACT document loaded into // a string variable, set the MIME body with it: const char * ediBody; ediBody = "UNB+IATB:1+6XPPC+LHPPC+940101:0950+1' ..."; mime.SetBodyFromPlainText(ediBody); // The call to SetBodyFromPlainText automatically set the // content-type to "text/plain". // However, we want: application/edifact; name=om080923.edi mime.put_ContentType("application/edifact"); mime.put_Name("om080923.edi"); // We want the content-disposition to be: // Content-Disposition: attachment; filename="om080923.edi" mime.put_Disposition("attachment"); mime.put_Filename("om080923.edi"); // Content-Transfer-Encoding: quoted-printable mime.put_Encoding("quoted-printable"); // Note: MIME header fields are case insensitive. // Add a few other header fields: mime.AddHeaderField("Message-ID","<CHILKAT-MID-83cf2fbf-10cb-4322-ad79-4c1097fd56f2@Matt>"); mime.AddHeaderField("MIME-VERSION","1.0"); // Display the complete non-signed, non-encrypted MIME: strOut.append(mime.GetMime()); strOut.append("\r\n"); strOut.append("*********************************************"); strOut.append("\r\n"); // Sign the MIME using an opaque signature. // (but first load a certificate) CkCert cert; success = cert.LoadByCommonName("Chilkat Software, Inc."); if (success == false) { strOut.append(cert.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } success = mime.ConvertToSigned(cert); if (success == false) { strOut.append(mime.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); 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: mime.put_ContentType("applicaton/pkcs7-mime"); // Display the signed MIME: strOut.append(mime.GetMime()); strOut.append("\r\n"); strOut.append("*********************************************"); strOut.append("\r\n"); // Now encrypt it. CkCert encryptCert; success = encryptCert.LoadByCommonName("speedi speedi"); if (success == false) { strOut.append(encryptCert.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } success = mime.Encrypt(encryptCert); if (success == false) { strOut.append(mime.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); 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: mime.put_ContentType("applicaton/pkcs7-mime"); // Display the signed/encrypted MIME strOut.append(mime.GetMime()); strOut.append("\r\n"); strOut.append("*********************************************"); strOut.append("\r\n"); // Save the MIME to a file: success = mime.SaveMime("edifact_smime.txt"); if (success == false) { strOut.append(mime.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } strOut.append("Success!\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.