Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Extract XML from FatturaPA .p7m
See more Digital Signatures Examples
Demonstrates how to verify the signature and extract the XML from a FatturaPA .p7m 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.BinData,
Chilkat.Xml,
Chilkat.Crypt2;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
bd: TBinData;
crypt: TCrypt2;
bVerified: Boolean;
xml: TXml;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
bd := TBinData.Create;
success := bd.LoadFile('qa_data/p7m/IT01879020517_abc.xml.p7m');
if (success <> True) then
begin
WriteLn('Failed to load the .p7m file');
Exit;
end;
crypt := TCrypt2.Create;
// Verify and extrct the payload contained within the .p7m.
// In this case, the payload is the FatturaPA XML.
// If successful, the resulting bd will contain only the XML.
bVerified := crypt.OpaqueVerifyBd(bd);
if (bVerified <> True) then
begin
WriteLn(crypt.LastErrorText);
WriteLn('Failed to extract and verify.');
Exit;
end;
// Save the XML to a file.
bd.WriteFile('qa_output/zIT01879020517_abc.xml');
// Alternatively, load into an XML object and emit.
xml := TXml.Create;
xml.LoadXml(bd.GetString('utf-8'));
WriteLn(xml.GetXml());
bd.Free;
crypt.Free;
xml.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.