Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) Encrypt MIME using PEM CertificateEncrypt MIME using a PEM certificate.
#include <C_CkMimeW.h> #include <C_CkCertW.h> void ChilkatSample(void) { HCkMimeW mime; BOOL success; HCkCertW cert; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. mime = CkMimeW_Create(); // Create a simple MIME message to be encrypted: success = CkMimeW_AddHeaderField(mime,L"Content-Type",L"text/plain"); success = CkMimeW_AddHeaderField(mime,L"abc",L"123"); CkMimeW_SetBody(mime,L"This is a test"); cert = CkCertW_Create(); success = CkCertW_LoadFromFile(cert,L"qa_data/pem/mf_public_rsa.pem"); if (success == FALSE) { wprintf(L"%s\n",CkCertW_lastErrorText(cert)); CkMimeW_Dispose(mime); CkCertW_Dispose(cert); return; } // Encrypt the MIME. success = CkMimeW_Encrypt(mime,cert); if (success == FALSE) { wprintf(L"%s\n",CkMimeW_lastErrorText(mime)); CkMimeW_Dispose(mime); CkCertW_Dispose(cert); return; } // Display the MIME: wprintf(L"%s\n",CkMimeW_getMime(mime)); // The resulting S/MIME looks like this: // Content-Type: application/x-pkcs7-mime; name="smime.p7m"; smime-type="enveloped-data" // abc: 123 // Content-Disposition: attachment; filename="smime.p7m" // Content-Transfer-Encoding: base64 // // MIICMAYJKoZIhvcNAQcDoIICITCCAh0CAQAxggGoMIIBpAIBADCBizB3MQswCQYDVQQGEwJQTDEi // MCAGA1UEChMZVW5pemV0byBUZWNobm9sb2dpZXMgUy5BLjEnMCUGA1UECxMeQ2VydHVtIENlcnRp // ZmljYXRpb24gQXV0aG9yaXR5MRswGQYDVQQDExJDZXJ0dW0gTGV2ZWwgSVYgQ0ECEDVuXbie8bb5 // sHeajm5k3ZYwDQYJKoZIhvcNAQEBBQAEggEADNac7gEUOvTWfyqwe0cS+m65Lte7ZmDGRElvqeo7 // C2+JZJfuxl2Roy+4vTovnn+9U2Yf5Kqc1m2ZPCE5Q8ExvOV4M0cTocLNLK6sfCR7cvo1xgf220qf // XYqWF1/ePuP9j1FrkFvBOoS4BREAnXsEa4zvuhvNPsMfjInK8wWnMftbLUiriAZBq391D+dxxX8M // kB1EHCWaS3H8WQI/caTnkRS6YdOCOrctJHtotkcU+4gcIxfTcq6yeloceURbesAYAvdRbIGszKCQ // FA2sC1x8SkDQCHfNUvmyS/fmkq5waFpmq1ksOspInb4ZM7SOjEUu+22vkAgbTmOS3MUdieuRcTBs // BgkqhkiG9w0BBwEwHQYJYIZIAWUDBAECBBClRoHLQZyzdHwoZA6pZjLYgEChuMzbQRXOjNF3RpnI // ZjNTKFDuhaUqk0rRTTn3D89F7ZMUBtoCP0bw+bH5UE9zpDaAgCF9s3W3/D5YNgAuw4AZ CkMimeW_Dispose(mime); CkCertW_Dispose(cert); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.