SQL Server
SQL Server
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 SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @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.
DECLARE @ssh int
EXEC @hr = sp_OACreate 'Chilkat.Ssh', @ssh OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Connect to the SSH server. Port 22 is the usual SSH port.
DECLARE @sshPort int
SELECT @sshPort = 22
EXEC sp_OAMethod @ssh, 'Connect', @success OUT, 'ssh.example.com', @sshPort
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @ssh, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @ssh
RETURN
END
-- Get the SHA256 fingerprint, including the key type and hash name in the result.
DECLARE @includeKeyType int
SELECT @includeKeyType = 1
DECLARE @includeHashName int
SELECT @includeHashName = 1
DECLARE @fingerprint nvarchar(4000)
EXEC sp_OAMethod @ssh, 'GetHostKeyFP', @fingerprint OUT, 'SHA256', @includeKeyType, @includeHashName
EXEC sp_OAGetProperty @ssh, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @ssh, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @ssh
RETURN
END
PRINT 'Host key fingerprint: ' + @fingerprint
EXEC sp_OAMethod @ssh, 'Disconnect', NULL
EXEC @hr = sp_OADestroy @ssh
END
GO