Lazarus Pascal Requires Chilkat v11.0.0+
Lazarus Pascal
Prepare a DKIM public key and DNS TXT record
See more DKIM Examples
Start with an RSA signing key in dkim-private.pem. This writes its public half to dkim-public.pem for local testing and prints the TXT record to enter at your DNS provider. Keep the private PEM on the signer. Use a 2048-bit or larger RSA key for a new deployment. DKIM RSA key sizes.
Use your signing domain and selector in place of example.com and mail2026. A provider that appends the zone usually wants just mail2026._domainkey as the name. If the value exceeds 255 bytes, split it into adjacent character strings within one TXT record. DNS joins those strings without adding spaces. Publish a new selector before rotating keys and keep the old record while previously signed mail is still in transit.
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.PublicKey;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
privateKey: TPrivateKey;
publicKey: TPublicKey;
pValue: string;
selector: string;
domain: string;
begin
success := False;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
// Supply your RSA signing key. For an encrypted PEM, get its password from your credential store.
privateKey := TPrivateKey.Create;
success := privateKey.LoadAnyFormatFile('dkim-private.pem','');
if (success <> True) then
begin
WriteLn(privateKey.LastErrorText);
Exit;
end;
publicKey := TPublicKey.Create;
success := privateKey.ToPublicKey(publicKey);
if (success <> True) then
begin
WriteLn(privateKey.LastErrorText);
Exit;
end;
if (publicKey.KeyType <> 'rsa') then
begin
WriteLn('Choose an RSA key for this rsa-sha256 example.');
Exit;
end;
// false selects SubjectPublicKeyInfo. The p= value is base64 DER, on one line.
pValue := publicKey.GetEncoded(False,'base64');
if (pValue = '') then
begin
WriteLn(publicKey.LastErrorText);
Exit;
end;
success := publicKey.SavePemFile(False,'dkim-public.pem');
if (success <> True) then
begin
WriteLn(publicKey.LastErrorText);
Exit;
end;
selector := 'mail2026';
domain := 'example.com';
WriteLn('TXT owner: ' + selector + '._domainkey.' + domain);
WriteLn('TXT value: v=DKIM1; k=rsa; p=' + pValue);
WriteLn('Saved dkim-public.pem.');
privateKey.Free;
publicKey.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.