Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Apple Keychain - Import Pfx
See more Apple Keychain Examples
Imports the certficates and private keys contained in .pfx (or .p12) to the Apple Keychain. If intermediate CA certs are contained in the PFX, they are also added to the Keychain if needed.Note: This example requires Chilkat v10.0.0 or greater.
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.CertStore;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
pfxPath: string;
pfxPassword: string;
cert: TCert;
certStore: TCertStore;
begin
success := False;
pfxPath := '/Users/chilkat/qa_data/pfx/EXAMPLE.pfx';
pfxPassword := 'PASSWORD';
// Load the PFX file.
cert := TCert.Create;
success := cert.LoadPfxFile(pfxPath,pfxPassword);
if (success = False) then
begin
WriteLn(cert.LastErrorText);
Exit;
end;
certStore := TCertStore.Create;
// Note: On MacOS and iOS, the AddCertificate method adds to the Keychain.
// There is no need to "open" the Keychain beforehand.
success := certStore.AddCertificate(cert);
if (success = False) then
begin
WriteLn(certStore.LastErrorText);
Exit;
end;
WriteLn('Success.');
cert.Free;
certStore.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.