Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Add a PFX Source from BinData
See more Email Object Examples
Demonstrates the Chilkat Email.AddPfxSourceBd method, which adds PFX data held in a BinData object to the list of certificate and private-key sources used during decryption or signing. The second argument is the PFX password. Call it before obtaining the encrypted email so Chilkat can decrypt it automatically. This example loads a PFX into a BinData, adds it, and then loads an encrypted email.
Background: This is the in-memory (
BinData) counterpart to AddPfxSourceFile. It is the right choice when the PFX bytes come from somewhere other than a file — a database, a secrets manager, or an HTTP download — letting you supply the certificate and private key without first writing them to disk (which is preferable for sensitive key material).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.BinData;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
email: TEmail;
bdPfx: TBinData;
begin
success := False;
// Demonstrates the AddPfxSourceBd method, which adds PFX data (held in a BinData) to the
// list of certificate and private-key sources used during decryption or signing. The
// second argument is the PFX password. Call it before obtaining the encrypted email.
email := TEmail.Create;
// Load PFX data into a BinData object.
bdPfx := TBinData.Create;
success := bdPfx.LoadFile('qa_data/certs/decryption.pfx');
if (success = False) then
begin
WriteLn(bdPfx.LastErrorText);
Exit;
end;
// Add the PFX as a source of the certificate + private key.
success := email.AddPfxSourceBd(bdPfx,'pfx_password');
if (success = False) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
// Load an encrypted email; Chilkat decrypts it using the PFX source.
success := email.LoadEml('qa_data/eml/encrypted.eml');
if (success = False) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
WriteLn('Decrypted = ' + email.Decrypted);
// Note: Paths such as "qa_data/..." are relative local filesystem paths,
// relative to the current working directory of the running application.
email.Free;
bdPfx.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.