DataFlex
DataFlex
Get the SSH Server Host Key Fingerprint
See more SSH Examples
Demonstrates the Chilkat Ssh.GetHostKeyFP method, which returns the connected server's host-key fingerprint. The first argument is the hash algorithm (for example SHA256 or MD5), the second controls whether the key type is included, and the third controls whether the hash name is included. The digest is Base64 without trailing padding.
Background: The host-key fingerprint identifies the server. Comparing it against a known-good value is how a client implements host-key pinning — detecting man-in-the-middle attempts or a changed server key.
SHA256 is the modern default; MD5 fingerprints are still seen in older tooling but are weaker.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoSsh
Integer iSshPort
Boolean iIncludeKeyType
Boolean iIncludeHashName
String sFingerprint
String sTemp1
Boolean bTemp1
Move False To iSuccess
// Demonstrates the Ssh.GetHostKeyFP method, which returns the server's host-key fingerprint.
// The 1st argument is the hash algorithm, the 2nd controls whether the key type is included,
// and the 3rd controls whether the hash name is included.
Get Create (RefClass(cComChilkatSsh)) To hoSsh
If (Not(IsComObjectCreated(hoSsh))) Begin
Send CreateComObject of hoSsh
End
// Connect to the SSH server. Port 22 is the usual SSH port.
Move 22 To iSshPort
Get ComConnect Of hoSsh "ssh.example.com" iSshPort To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoSsh To sTemp1
Showln sTemp1
Procedure_Return
End
// Get the SHA256 fingerprint, including the key type and hash name in the result.
Move True To iIncludeKeyType
Move True To iIncludeHashName
Get ComGetHostKeyFP Of hoSsh "SHA256" iIncludeKeyType iIncludeHashName To sFingerprint
Get ComLastMethodSuccess Of hoSsh To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoSsh To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Host key fingerprint: " sFingerprint
Send ComDisconnect To hoSsh
End_Procedure