Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Delphi DLL Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Delphi DLL) PKCS7 Encrypt MIME

Encrypt MIME using a digital certificate to create PKCS7 encrypted S/MIME.

Chilkat for Delphi Downloads

Chilkat non-ActiveX DLL for Delphi

Chilkat ActiveX DLL for Delphi

* The examples here use the non-ActiveX DLL.

uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Cert, Mime;

...

procedure TForm1.Button1Click(Sender: TObject);
var
mime: HCkMime;
success: Boolean;
cert: HCkCert;

begin
mime := CkMime_Create();

success := CkMime_UnlockComponent(mime,'Anything for 30-day trial.');
if (success = False) then
  begin
    Memo1.Lines.Add(CkMime__lastErrorText(mime));
    Exit;
  end;

//  Build a simple MIME message to be encrypted:
success := CkMime_AddHeaderField(mime,'Content-Type','text/plain');
success := CkMime_AddHeaderField(mime,'abc','123');
CkMime_SetBody(mime,'This is a test');

//  A digital certificate is required to create PKCS7 encrypted MIME.
//  It can come from a variety of sources: .cer file, .pfx file, PEM files,
//  an in-memory representation, or directly from a Windows
//  registry-based certificate store.

//  This example will load a certificate object from a .cer file.
//  Note: Only the public-key is required to encrypt.  (Decryption
//  requires a private key.)

cert := CkCert_Create();
success := CkCert_LoadFromFile(cert,'myCert.cer');
if (success = False) then
  begin
    Memo1.Lines.Add(CkCert__lastErrorText(cert));
    Exit;
  end;

//  Encrypt the MIME:
success := CkMime_Encrypt(mime,cert);
if (success = False) then
  begin
    Memo1.Lines.Add(CkMime__lastErrorText(mime));
    Exit;
  end;

//  Display the MIME:
Memo1.Lines.Add(CkMime__getMime(mime));

//  The resulting S/MIME looks something like this:

/*
abc: 123
Content-Disposition: attachment; filename="smime.p7m";
Content-Transfer-Encoding: base64
Content-Type: application/x-pkcs7-mime;
 name="smime.p7m";

MIICAQYJKoZIhvcNAQcDoIIB8jCCAe4CAQAxggGFMIIBgQIBADBpMFUxCzAJBgNVBAYTAlpBMSUw
IwYDVQQKExxUaGF3dGUgQ29uc3VsdGluZyAoUHR5KSBMdGQuMR8wHQYDVQQDExZUaGF3dGUgQ29k
ZSBTaWduaW5nIENBAhB4ouTcAmLszrGi170k1deSMA0GCSqGSIb3DQEBAQUABIIBABz59iwVufLZ
QIPs0whUYMtBjIQxg5IOCxpoKJeJmLVzu9Q5Q1poxG9uYOveybS9c4wbl5A0DFfKTW5O4HhHcOHW
TgcH4iqdwhiFWm/q9d5rjceJWBFQsGOcgoXSU/U2Xp+N47/+Pqyc5XJbxKnOc4YhPzO320JZsNB6
p1NGk5SNnWqgbUDmEnfH8ZPHSV7dNi2aiFALYTyLjyp0lqJCsdZ524OPTZFfusrl/9ibPAW7jKuI
FgDCcBtRJvolVF8iIHxaTw4rhk0qb1KWzxvB5j9HSLdyIKIPhZbxeS10bx18YkSsBlKfdKRalQag
3oWSRdsK9/N75YHG8Pm+x9BOHUAwYAYJKoZIhvcNAQcBMBkGCCqGSIb3DQMCMA0CAToECAb+toBW
txZigDhGZKSpUpuTiWvvSMemX/c79sSnMpuefVwGKFTDgXVLE2SoD5a9Yh5vcG7Mhl2IkilVwOMc
fi23+g==
*/

CkMime_Dispose(mime);
CkCert_Dispose(cert);

end;

 

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