Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
PKCS7 Decrypt MIME
See more MIME Examples
Loads a PKCS7 encrypted MIME file and decrypts. The cert and private key used for decryption is loaded from a PFX file.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;
pfxPassword: string;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
mime := TMime.Create;
// Load the MIME
success := mime.LoadMimeFile('encryptedMime.txt');
if (success = False) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
// The AddPfxSourceFile and/or AddPfxSourceData
// methods may be called one or more times (one per PFX)
// to add sources from which the MIME component will
// search for certificates and private keys when decrypting.
pfxPassword := 'myPassword';
success := mime.AddPfxSourceFile('myCertAndPrivateKey.pfx',pfxPassword);
if (success = False) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
// Decrypt...
success := mime.Decrypt();
if (success = False) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
// Display the decrypted MIME:
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.