Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Cache a DKIM Public Key from a File
See more DKIM / DomainKey Examples
Demonstrates the Chilkat Dkim.LoadPublicKeyFile method, which caches an RSA public key read from a local file for a specific selector and domain. The arguments are the selector, the domain, and the public-key file path. Supported formats include PEM X.509 SubjectPublicKeyInfo and PEM PKCS#1 RSA public key.
Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background: This is the file-based form of
LoadPublicKey, convenient when the key already lives in a .pem file — a saved copy of what the domain publishes in DNS. As with the string form, the cache is keyed on the exact selector and domain, so those must match the signature being verified. Pre-loading keys this way lets a verifier work without any DNS access at all.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.Dkim;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
dkim: TDkim;
begin
success := False;
// Demonstrates the Dkim.LoadPublicKeyFile method, which caches an RSA public key read from a
// local file for a specific selector and domain. The 1st argument is the selector, the 2nd is
// the domain, and the 3rd is the local public-key file path.
dkim := TDkim.Create;
// Read the public key from a file and cache it under the exact selector and domain. Supported
// formats include PEM X.509 SubjectPublicKeyInfo and PEM PKCS#1 RSA public key.
success := dkim.LoadPublicKeyFile('myselector','example.com','qa_data/dkim_public.pem');
if (success = False) then
begin
WriteLn(dkim.LastErrorText);
Exit;
end;
WriteLn('Public key loaded and cached.');
dkim.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.