![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Delphi DLL) SSH Authentication using an SSH CertificateSee more SSH ExamplesDemonstrates how to authenticate using an SSH certificate.Note: This example requires Chilkat v11.0.0 or greater. For more information, see https://www.chilkatsoft.com/understanding_ssh_certificates.asp
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, SshKey, StringBuilder, Ssh; ... procedure TForm1.Button1Click(Sender: TObject); var sbSshCert: HCkStringBuilder; success: Boolean; sbPrivKey: HCkStringBuilder; key: HCkSshKey; ssh: HCkSsh; hostname: PWideChar; port: Integer; begin // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. sbSshCert := CkStringBuilder_Create(); success := CkStringBuilder_LoadFile(sbSshCert,'qa_data/sshCert/user_ecdsa_key-cert.pub','utf-8'); if (success = False) then begin Memo1.Lines.Add('Failed to load user_ecdsa_key-cert.pub'); Exit; end; sbPrivKey := CkStringBuilder_Create(); success := CkStringBuilder_LoadFile(sbPrivKey,'qa_data/sshKeys/user_ecdsa_key','utf-8'); if (success = False) then begin Memo1.Lines.Add('Failed to load user_ecdsa_key'); Exit; end; key := CkSshKey_Create(); // Provide the password if the user_ecdsa_key is stored in an encrypted format. CkSshKey_putPassword(key,'secret'); success := CkSshKey_FromOpenSshPrivateKey(key,CkStringBuilder__getAsString(sbPrivKey)); if (success = False) then begin Memo1.Lines.Add(CkSshKey__lastErrorText(key)); Exit; end; // Indicate that the SSH certificate is to be used for authentication. // The UseSshCertificate method was added in Chilkat v11.0.0 CkSshKey_UseSshCertificate(key,CkStringBuilder__getAsString(sbSshCert)); ssh := CkSsh_Create(); hostname := 'ssh.example.com'; port := 22; success := CkSsh_Connect(ssh,hostname,port); if (success <> True) then begin Memo1.Lines.Add(CkSsh__lastErrorText(ssh)); Exit; end; success := CkSsh_AuthenticatePk(ssh,'myLogin',key); if (success <> True) then begin Memo1.Lines.Add(CkSsh__lastErrorText(ssh)); Exit; end; Memo1.Lines.Add('Public-Key Authentication using an SSH Certificate was Successful!'); CkStringBuilder_Dispose(sbSshCert); CkStringBuilder_Dispose(sbPrivKey); CkSshKey_Dispose(key); CkSsh_Dispose(ssh); end; |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.