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

Create PKCS7 Signature using .cer and .key Files

Uses a digital certificate (.cer file) and private key file to create a PKCS7 signature.

Download Chilkat FileAccess ActiveX (freeware)

Download Chilkat Crypt ActiveX

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

...

procedure TForm1.Button1Click(Sender: TObject);
var
cert: TChilkatCert;
success: Integer;
privKey: CHILKATCERTIFICATELib_TLB.IPrivateKey;
password: String;
crypt: TChilkatCrypt2;
pkcs7Sig: Array of Byte;
textToSign: String;
fac: TCkFileAccess;
facSuccess: Integer;

begin
//  First, load the .cer and .key files into Chilkat objects...
cert := TChilkatCert.Create(Self);

success := cert.LoadFromFile('myCert.cer');
if (success <> 1) then
  begin
    Memo1.Lines.Add(cert.LastErrorText);
    Exit;
  end;

privKey := TprivateKey.Create(Self).ControlInterface;
password := 'myPassword';
//  The private key object provides different methods for
//  loading keys of many different formats.
//  This example loads a PKCS8 encrypted private key.
success := privKey.LoadPkcs8EncryptedFile('myPrivateKey.key',password);
if (success <> 1) then
  begin
    Memo1.Lines.Add(privKey.LastErrorText);
    Exit;
  end;

//  NOTE:  In this example, the .cer should contain the public key
//  that corresponds to the private key.

crypt := TChilkatCrypt2.Create(Self);

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

//  Set the certifcate + private key to be used for signing:
crypt.SetSigningCert2(cert.ControlInterface As CHILKATCRYPT2Lib_TLB.IChilkatCert,privKey);

textToSign := 'This is the text to be signed.';
pkcs7Sig := crypt.SignString(textToSign);
if ( VarArrayHighBound(pkcs7Sig,1) == -1 ) then
  begin
    Memo1.Lines.Add(crypt.LastErrorText);
    Exit;
  end;

//  Save the PKCS7 signature to a file.
fac := TCkFileAccess.Create(Self);

facSuccess := fac.WriteEntireFile('sig.p7s', pkcs7Sig);
if (facSuccess = 0) then
  begin
    ShowMessage(fac.LastErrorText);
    Exit;
  end;

end;

 

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

Mail Component · .NET Email Component · XML Parser