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

Apple Keychain - Import ECDSA Private Key

See more Apple Keychain Examples

Imports an ECDSA private key to the Apple Keychain.

Note: This example requires Chilkat v10.0.0 or greater.

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.PrivateKey;

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

procedure RunDemo;
var
  success: Boolean;
  pemPath: string;
  pemPassword: string;
  privKey: TPrivateKey;

begin
  success := False;

  pemPath := '/Users/chilkat/qa_data/ecc/prime256v1-privKey.pem';
  //  Provide a password if your PEM is encrypted. Otherwise pass the empty string.
  pemPassword := '';

  privKey := TPrivateKey.Create;
  success := privKey.LoadAnyFormatFile(pemPath,pemPassword);
  if (success = False) then
    begin
      WriteLn(privKey.LastErrorText);
      Exit;
    end;

  //  In Apple Keychain, the label for an item such as a private key is a user-friendly identifier that helps distinguish one item from
  //  another in the Keychain. It is typically a brief name or description associated with the item. 
  //  The label is displayed in the Keychain Access application and is useful for quickly identifying the purpose
  //  or source of a specific key, certificate, or password entry.

  //  The label does not affect the functionality or security of the item; it is purely for organizational purposes. 
  //  You can edit or assign labels to make your Keychain easier to navigate.

  //  On MacOS, you can save the private key to the Keychain by calling SavePkcs8File with a "filename" in the format"keychain:<label>"
  success := privKey.SavePkcs8File('keychain:MyEcdsaKey123');
  if (success = False) then
    begin
      WriteLn(privKey.LastErrorText);
      Exit;
    end;

  WriteLn('Success.');

  //  Here you can see:
  //  
  //  image


  privKey.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.