Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Extract XML string from a .p7m byte array (e.g. FATTURA ELETTRONICA, ITALY)

See more Digital Signatures Examples

_LANGUAGE_ example to extract the original XML from a .p7m (Signed-Data PKCS7 Format) provided as a byte array.

One use for this example is to extract the original XML from a Fattura Elettronica .p7m signature.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
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.Crypt2,
  Chilkat.FileAccess;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  fac: TFileAccess;
  p7mBytes: TBytes;
  crypt: TCrypt2;
  originalXml: string;

begin
  //  This example requires the Chilkat API to have been previously unlocked.
  //  See Global Unlock Sample for sample code.

  fac := TFileAccess.Create;

  p7mBytes := fac.ReadEntireFile('testData/p7m/fattura_signature.p7m');
  if (fac.LastMethodSuccess <> True) then
    begin
      WriteLn(fac.LastErrorText);
      Exit;
    end;

  crypt := TCrypt2.Create;

  originalXml := crypt.OpaqueVerifyString(p7mBytes);
  if (crypt.LastMethodSuccess <> True) then
    begin
      WriteLn(fac.LastErrorText);
      Exit;
    end;

  WriteLn('Original XML:');
  WriteLn(originalXml);

  WriteLn('Success!');


  fac.Free;
  crypt.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.