Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Verify and Unwrap PCKS7 Signed MIME
See more MIME Examples
Demonstrates calling the Verify method to verify and unwrap PKCS7 signed MIME. The MIME is restored to the original structure that it would have originally had prior to signing. The Verify method works with both detached signatures, as well as opaque/attached signatures.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.Mime;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
mime: TMime;
verified: Boolean;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
mime := TMime.Create;
// A PKCS7 signature usually embeds both the signing
// certificate with its public key. Therefore, it is usually
// possible to verify a signature without the need to
// already have the certificate installed.
// Load the signed MIME from a file...
success := mime.LoadMimeFile('signedMime.txt');
if (success = False) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
// Verify the signed MIME and restore the MIME
// to the structure/content it had prior to signing.
verified := mime.Verify();
if (verified = False) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
// Examine the MIME after signature verification (i.e. "unwrapping")
WriteLn(mime.GetMime());
mime.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.