Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Binary Certificate Extension Data
See more Certificates Examples
Demonstrates how to binary certificate extension data by OID.The GetExtensionBd method is added in Chilkat v9.5.0.96.
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.Cert,
Chilkat.BinData;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
cert: TCert;
bd: TBinData;
oid: string;
strXml: string;
begin
success := False;
cert := TCert.Create;
success := cert.LoadFromFile('qa_data/certs/testCert.cer');
if (success = False) then
begin
WriteLn(cert.LastErrorText);
Exit;
end;
bd := TBinData.Create;
// The particular certificate in this test contains the following extensions
oid := '1.2.250.1.71.1.2.5';
success := cert.GetExtensionBd(oid,bd);
if (success = True) then
begin
WriteLn(oid + ': ' + bd.GetEncoded('hex_lower'));
end;
oid := '1.2.250.1.71.1.2.2';
success := cert.GetExtensionBd(oid,bd);
if (success = True) then
begin
WriteLn(oid + ': ' + bd.GetEncoded('hex_lower'));
end;
oid := '1.2.250.1.71.1.2.3';
success := cert.GetExtensionBd(oid,bd);
if (success = True) then
begin
WriteLn(oid + ': ' + bd.GetEncoded('hex_lower'));
end;
oid := '1.2.250.1.71.1.2.7';
success := cert.GetExtensionBd(oid,bd);
if (success = True) then
begin
WriteLn(oid + ': ' + bd.GetEncoded('hex_lower'));
end;
oid := '1.2.250.1.71.4.2.5';
success := cert.GetExtensionBd(oid,bd);
if (success = True) then
begin
WriteLn(oid + ': ' + bd.GetEncoded('hex_lower'));
end;
// Sample output:
// 1.2.250.1.71.1.2.5: 040180
// 1.2.250.1.71.1.2.2: 020100
// 1.2.250.1.71.1.2.3: 1315383032353030303030312f32393030303539313432
// 1.2.250.1.71.1.2.7: 02010a
// 1.2.250.1.71.4.2.5: 30060c04534d3236
// The above binary values are actually ASN.1
// You can get the ASN.1 decoed by calling GetExtensionAsXml to get it in XML format,
// and then you extract the values from the XML.
oid := '1.2.250.1.71.1.2.5';
strXml := cert.GetExtensionAsXml(oid);
if (cert.LastMethodSuccess = True) then
begin
WriteLn(oid + ': ' + strXml);
end;
oid := '1.2.250.1.71.1.2.2';
strXml := cert.GetExtensionAsXml(oid);
if (cert.LastMethodSuccess = True) then
begin
WriteLn(oid + ': ' + strXml);
end;
oid := '1.2.250.1.71.1.2.3';
strXml := cert.GetExtensionAsXml(oid);
if (cert.LastMethodSuccess = True) then
begin
WriteLn(oid + ': ' + strXml);
end;
oid := '1.2.250.1.71.1.2.7';
strXml := cert.GetExtensionAsXml(oid);
if (cert.LastMethodSuccess = True) then
begin
WriteLn(oid + ': ' + strXml);
end;
oid := '1.2.250.1.71.4.2.5';
strXml := cert.GetExtensionAsXml(oid);
if (cert.LastMethodSuccess = True) then
begin
WriteLn(oid + ': ' + strXml);
end;
// Sample output:
// 1.2.250.1.71.1.2.5: <octets>gA==</octets>
// 1.2.250.1.71.1.2.2: <int>00</int>
// 1.2.250.1.71.1.2.3: <printable>8025000001/2900059142</printable>
// 1.2.250.1.71.1.2.7: <int>0A</int>
// 1.2.250.1.71.4.2.5: <sequence><utf8>SM26</utf8></sequence>
// "gA==" is the base64 encoded byte values
// "0A" is hex for decimal 10
cert.Free;
bd.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.