Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Remove All S/MIME Security Layers (UnwrapSecurity)
See more MIME Examples
Demonstrates the Chilkat Mime.UnwrapSecurity method, which removes supported S/MIME security layers and restores the underlying MIME content. It takes no arguments and handles both layer orders: signed-then-encrypted and encrypted-then-signed.
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: A message can be both signed and encrypted, in either order, producing nested S/MIME wrappers.
UnwrapSecurity peels them all off in one call — verifying signatures and decrypting as it goes — so you do not have to detect the layering and call Verify and Decrypt in the right sequence yourself. Decryption still requires the recipient's certificate and private key to be configured.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;
begin
success := False;
// Demonstrates the Mime.UnwrapSecurity method, which removes supported S/MIME security layers and
// restores the underlying MIME content. It takes no arguments and handles both layer orders
// (signed-then-encrypted and encrypted-then-signed).
mime := TMime.Create;
success := mime.LoadMimeFile('qa_data/secured.eml');
if (success = False) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
// A single call peels off the signature and/or encryption layers. (Decryption requires the
// appropriate certificate/private key to be configured first.)
success := mime.UnwrapSecurity();
if (success = False) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
WriteLn('Security layers removed. Content-Type is now: ' + mime.ContentType);
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.