Lazarus Pascal
Lazarus Pascal
Set the DKIM Signing Private Key
See more DKIM / DomainKey Examples
Demonstrates the Chilkat Dkim.SetDkimPrivateKey method, which supplies the RSA private key used by DkimSign. The only argument is a PrivateKey object. The source key may be destroyed after this returns, and the configured key can be reused for multiple signatures.
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: DKIM proves a message really came from its domain by signing it with a private key that only the domain owner holds; recipients verify with the matching public key published in the domain's DNS. This method loads that private half into the
Dkim object once, so a mail server can sign every outgoing message without re-reading the key each time. Because the key is the domain's signing secret, it should be protected like any other private key and never committed to source.Chilkat Lazarus Pascal 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.PrivateKey,
Chilkat.Dkim;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
dkim: TDkim;
privKey: TPrivateKey;
begin
success := False;
// Demonstrates the Dkim.SetDkimPrivateKey method, which supplies the RSA private key used by
// DkimSign. The only argument is a PrivateKey object.
dkim := TDkim.Create;
// Load the RSA private key that corresponds to the public key published in the domain's DNS.
privKey := TPrivateKey.Create;
success := privKey.LoadPemFile('qa_data/dkim_private.pem');
if (success = False) then
begin
WriteLn(privKey.LastErrorText);
Exit;
end;
// Copy the key into the Dkim object. The PrivateKey object may be destroyed afterward, and the
// configured key can be reused for multiple signatures.
success := dkim.SetDkimPrivateKey(privKey);
if (success = False) then
begin
WriteLn(dkim.LastErrorText);
Exit;
end;
WriteLn('DKIM private key configured.');
dkim.Free;
privKey.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.