Lazarus Pascal Requires Chilkat v11.0.0+
Lazarus Pascal
Sign an EML using RSA-PSS and SHA-256
See more Email Object Examples
Load the intended signing certificate and its RSA private key from a PFX. Set the signature options on Email and render the final S/MIME message through MailMan. The resulting multipart/signed file can be verified independently. Supply the PFX password through your application’s credential store.
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.MailMan,
Chilkat.BinData,
Chilkat.Cert,
Chilkat.Email;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
email: TEmail;
cert: TCert;
mail: TMailMan;
rendered: TBinData;
begin
success := False;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
email := TEmail.Create;
success := email.LoadEml('message.eml');
if (success <> True) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
cert := TCert.Create;
success := cert.LoadPfxFile('signer.pfx','PFX_PASSWORD');
if (success <> True) then
begin
WriteLn(cert.LastErrorText);
Exit;
end;
success := email.SetSigningCert(cert);
if (success <> True) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
email.SigningAlg := 'pss';
email.SigningHashAlg := 'sha256';
email.SendSigned := True;
mail := TMailMan.Create;
mail.OpaqueSigning := False;
rendered := TBinData.Create;
success := mail.RenderToMimeBd(email,rendered);
if (success <> True) then
begin
WriteLn(mail.LastErrorText);
Exit;
end;
success := rendered.WriteFile('signed.eml');
if (success <> True) then
begin
WriteLn('Failed: rendered.WriteFile.');
Exit;
end;
WriteLn('Saved signed.eml.');
email.Free;
cert.Free;
mail.Free;
rendered.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.