Delphi Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CUnicode C++Unicode CMFCDelphi DLLDelphi ActiveXFoxProJavaPerlPHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

Delphi Examples

Bounced Mail
Bz2
Character Encoding
CSV
DKIM / DomainKey
Digital Certificates
Digital Signatures
DH Key Exchange
DSA
Email
Email Object
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
NTLM
POP3
RSA
S/MIME
SMTP
Socket
Spider
SFTP
SSH
SSH Key
SSH Tunnel
String
Tar
Upload
XML
XMP
Zip Compression

More Examples...
Amazon S3
Byte Array
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
LZW

Type Conversion

 

Article: Understanding COM References in Delphi

(Delphi) PKCS7 Encrypt MIME

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

Download Chilkat MIME ActiveX

uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls,
    CHILKATMIMELib_TLB,
    CHILKATCERTIFICATELib_TLB,
    OleCtrls;

...

procedure TForm1.Button1Click(Sender: TObject);
var
mime: CHILKATMIMELib_TLB.IChilkatMime;
success: Integer;
cert: TChilkatCert;

begin
mime := CoChilkatMime.Create();

success := mime.UnlockComponent('Anything for 30-day trial.');
if (success = 0) then
  begin
    Memo1.Lines.Add(mime.LastErrorText);
    Exit;
  end;

//  Build a simple MIME message to be encrypted:
mime.AddHeaderField('Content-Type','text/plain');
mime.AddHeaderField('abc','123');
mime.SetBody('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 := TChilkatCert.Create(Self);
success := cert.LoadFromFile('myCert.cer');
if (success = 0) then
  begin
    Memo1.Lines.Add(cert.LastErrorText);
    Exit;
  end;

//  Encrypt the MIME:
success := mime.Encrypt(cert.ControlInterface As CHILKATMIMELib_TLB.IChilkatCert);
if (success = 0) then
  begin
    Memo1.Lines.Add(mime.LastErrorText);
    Exit;
  end;

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

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

end;

 

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