Delphi Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP 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

Decrypt P7M using PFX to get MIME

Demonstrates how to decrypt a .p7m (PKCS7) binary file using a certificate and private key from a PFX file. The result of the decryption (in this case) is MIME text that may be loaded into a Chilkat MIME object.

Note: Any type of file or data may be encrypted to produce a .p7m (PKCS7) encrypted file. This example was prompted by a customer needing to decrypt a MIME message. The final step of loading the decrypted text into a MIME object would be skipped if decrypting something other than MIME..

Download Chilkat Crypt ActiveX

Download Chilkat MIME ActiveX

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

...

procedure TForm1.Button1Click(Sender: TObject);
var
crypt: TChilkatCrypt2;
success: Integer;
p7mData: Array of Byte;
pfxFilePath: String;
pfxPassword: String;
mimeText: String;
mime: CHILKATMIMELib_TLB.IChilkatMime;

begin

crypt := TChilkatCrypt2.Create(Self);

//  Any string argument automatically begins the 30-day trial.
success := crypt.UnlockComponent('30-day trial');
if (success <> 1) then
  begin
    ShowMessage(crypt.LastErrorText);
    Exit;
  end;

//  Read the P7M file into memory.
p7mData := crypt.ReadFile('encrypted.p7m');

//  Setup the crypt object:

//  Indicate that public-key decryption is to be used.
crypt.CryptAlgorithm := 'pki';

//  Add a PFX file to allow the crypt object to find
//  the certificate and private key needed for decryption
pfxFilePath := 'myPfx.pfx';
pfxPassword := 'secret';
success := crypt.AddPfxSourceFile(pfxFilePath,pfxPassword);
if (success <> 1) then
  begin
    ShowMessage(crypt.LastErrorText);
    Exit;
  end;

//  Assuming the decrypted data will be text, decrypt to
//  a string.
mimeText := crypt.DecryptString(p7mData);
if (Length(mimeText) = 0 ) then
  begin
    ShowMessage(crypt.LastErrorText);
    Exit;
  end;

//  Note: Chilkat Crypt and Chilkat MIME are separate products.
//  To use both objects, one would license the "Chilkat Bundle",
//  which provides licenses to all existing Chilkat products.
//  This is less expensive than licensing each of the two products separately.

mime := CoChilkatMime.Create();

success := mime.UnlockComponent('Anyting for 30-day trial');
if (success <> 1) then
  begin
    ShowMessage(mime.LastErrorText);
    Exit;
  end;

//  Load the MIME text into the MIME object.
success := mime.LoadMime(mimeText);
if (success <> 1) then
  begin
    ShowMessage(mime.LastErrorText);
    Exit;
  end;

//  Save the MIME to a file:
success := mime.SaveMime('outMime.txt');
if (success <> 1) then
  begin
    ShowMessage(mime.LastErrorText);
    Exit;
  end;

//  Success!  Output the MIME text:
Memo1.Lines.Add(mime.GetMime());


end;

 

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

Mail Component · .NET Email Component · XML Parser