Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Provide a Certificate Vault to an Email
See more Email Object Examples
Demonstrates the Chilkat Email.UseCertVault method, which adds an XML certificate vault to the email's internal certificate and private-key lookup sources for encryption, decryption, signing, and verification. This example builds a vault from a PFX and attaches it to the email.
Background: A certificate vault is a portable, in-memory store of certificates and private keys. Instead of wiring up each certificate individually for every operation, you load your credentials into one
XmlCertVault and hand it to the email; Chilkat then draws on it automatically whenever it needs a key — to decrypt an incoming message, sign an outgoing one, or verify a signature. This is especially convenient on platforms without an OS certificate store.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Email,
Chilkat.XmlCertVault;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
email: TEmail;
vault: TXmlCertVault;
begin
success := False;
// Demonstrates the UseCertVault method, which adds an XML certificate vault to the email's
// internal certificate and private-key lookup sources for encryption, decryption, signing,
// and verification.
email := TEmail.Create;
// Build a certificate vault from a PFX (certificate + private key).
vault := TXmlCertVault.Create;
success := vault.AddPfxFile('qa_data/certs/certs.pfx','pfx_password');
if (success = False) then
begin
WriteLn(vault.LastErrorText);
Exit;
end;
// Make the vault available to the email object for crypto operations.
success := email.UseCertVault(vault);
if (success = False) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
WriteLn('Certificate vault attached to the email.');
// Note: The path "qa_data/certs/certs.pfx" is a relative local filesystem path,
// relative to the current working directory of the running application.
email.Free;
vault.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.