Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Ssh
integer li_SshPort
integer li_IncludeKeyType
integer li_IncludeHashName
string ls_Fingerprint

li_Success = 0

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

loo_Ssh = create oleobject
li_rc = loo_Ssh.ConnectToNewObject("Chilkat.Ssh")
if li_rc < 0 then
    destroy loo_Ssh
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  Connect to the SSH server.  Port 22 is the usual SSH port.
li_SshPort = 22
li_Success = loo_Ssh.Connect("ssh.example.com",li_SshPort)
if li_Success = 0 then
    Write-Debug loo_Ssh.LastErrorText
    destroy loo_Ssh
    return
end if

//  Get the SHA256 fingerprint, including the key type and hash name in the result.
li_IncludeKeyType = 1
li_IncludeHashName = 1
ls_Fingerprint = loo_Ssh.GetHostKeyFP("SHA256",li_IncludeKeyType,li_IncludeHashName)
if loo_Ssh.LastMethodSuccess = 0 then
    Write-Debug loo_Ssh.LastErrorText
    destroy loo_Ssh
    return
end if

Write-Debug "Host key fingerprint: " + ls_Fingerprint

loo_Ssh.Disconnect()


destroy loo_Ssh