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

Export Certificate and Private Key to PFX

Demonstrates how to export a digital certificate, it's private key, and potentially all certificate's in the chain of authentication to a PFX file.

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

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Integer;
ccs: TChilkatCreateCS;
certStore: CHILKATCERTIFICATELib_TLB.IChilkatCertStore;
cert: IChilkatCert;
bIncludeChain: Integer;

begin


//  This object is used to create a certificate store object.
ccs := TChilkatCreateCS.Create(Self);

//  Open the local machine certificate store read-only.
ccs.ReadOnly := 1;
certStore := ccs.OpenLocalSystemStore();

//  Can we find a certificate by email address?

cert := certStore.FindCertBySubjectE('admin@chilkatsoft.com') As IChilkatCert;
if (cert = nil ) then
  begin
    //  Open the current-user certificate store and check it instead.

    Memo1.Lines.Add('Checking current-user certificate store...');

    certStore := ccs.OpenCurrentUserStore();

    cert := certStore.FindCertBySubjectE('admin@chilkatsoft.com') As IChilkatCert;
    if (cert = nil ) then
      begin
        Memo1.Lines.Add('Failed to find certificate!');

      end;

  end;

//  Does this certificate have a private key accessible
//  to the calling process?  Private keys are *not* stored
//  within the certificate store.  Private keys are stored
//  in a key container in a Windows protected store.  It
//  can be one of two protected stores: the protected store for
//  the current logged-in user account, or the "machine-key"
//  protected store.  The private key must both exist in a
//  protected store, and the process must have permission to
//  access it...

//  You can only export to a PFX if the private key exists
//  and is accessible.

if (cert.HasPrivateKey() = 1) then
  begin

    //  Export to a PFX.
    //  Provide a password that will be required whenever the PFX is opened.
    //  Also, include all certs in the chain of authentication.

    bIncludeChain := 1;
    success := cert.ExportToPfxFile('myCert.pfx','myPassword',bIncludeChain);
    if (success <> 1) then
      begin
        Memo1.Lines.Add(cert.LastErrorText);
      end
    else
      begin
        Memo1.Lines.Add('Exported to PFX!');
      end;

  end
else
  begin
    Memo1.Lines.Add('Certificate does not have a private key available');
  end;

//  The Chilkat Certificate, Certificate Store, Private Key,
//  Public Key, and Key Container classes / objects are freeware.

//  They are used by and included with the Chilkat Email,
//  Crypt, S/MIME, and other commercial Chilkat components.

end;

 

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

Mail Component · .NET Email Component · XML Parser