Lazarus Pascal
Lazarus Pascal
Example: Crypt2.GetSignedAttributes method
Demonstrates how to call the GetSignedAttributes method.Chilkat Lazarus Pascal 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.StringBuilder,
Chilkat.JsonObject,
Chilkat.Crypt2;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
crypt: TCrypt2;
bdPkcs7: TBinData;
json: TJsonObject;
sbJson: TStringBuilder;
i: Integer;
tryNext: Boolean;
begin
success := False;
crypt := TCrypt2.Create;
bdPkcs7 := TBinData.Create;
success := bdPkcs7.LoadFile('qa_data/cades/CAdES-T/Signature-C-T-1.p7m');
if (success = False) then
begin
WriteLn(bdPkcs7.LastErrorText);
Exit;
end;
json := TJsonObject.Create;
json.EmitCompact := False;
sbJson := TStringBuilder.Create;
i := 0;
tryNext := True;
while tryNext do
begin
if (crypt.GetSignedAttributes(i,bdPkcs7,sbJson) = True) then
begin
json.LoadSb(sbJson);
WriteLn(i + ': ');
WriteLn(json.Emit());
end
else
begin
tryNext := False;
end;
i := i + 1;
end;
// Sample output:
// 0:
// {
// "signedAttributes": [
// {
// "oid": "1.2.840.113549.1.9.3",
// "name": "Content Type"
// },
// {
// "oid": "1.2.840.113549.1.9.5",
// "name": "Signing Time"
// },
// {
// "oid": "1.2.840.113549.1.9.4",
// "name": "Message Digest"
// },
// {
// "oid": "1.2.840.113549.1.9.16.2.47",
// "name": "Signing Certificate V2"
// }
// ]
// }
crypt.Free;
bdPkcs7.Free;
json.Free;
sbJson.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.