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

SSH Key Fingerprint

See more SSH Key Examples

Generates a fingerprint for an SSH key.

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

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

procedure RunDemo;
var
  success: Boolean;
  key: TSshKey;
  keyStr: string;
  fingerprint: string;

begin
  success := False;

  key := TSshKey.Create;

  //  Load an SSH key from an encrypted OpenSSH-formatted private key:
  key.Password := 'secret';

  //  First load the PEM into a string:
  keyStr := key.LoadText('privkey_openssh_encrypted.pem');

  //  Import into the SSH key object:
  success := key.FromOpenSshPrivateKey(keyStr);
  if (success <> True) then
    begin
      WriteLn(key.LastErrorText);
      Exit;
    end;

  //  Generate the fingerprint:

  fingerprint := key.GenFingerprint();

  WriteLn(fingerprint);

  //  A sample fingerpring looks like this:
  //  ssh-dss 2048 d0:5f:f7:d6:49:60:7b:50:19:f4:41:59:d4:1f:61:7a


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