VB.NET
VB.NET
SSH Authentication using an SSH Certificate
See more SSH Examples
Demonstrates how to authenticate using an SSH certificate.Chilkat VB.NET Downloads
Dim success As Boolean = False
' This example assumes the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.
Dim sbSshCert As New Chilkat.StringBuilder
success = sbSshCert.LoadFile("qa_data/sshCert/user_ecdsa_key-cert.pub","utf-8")
If (success = False) Then
Debug.WriteLine("Failed to load user_ecdsa_key-cert.pub")
Exit Sub
End If
Dim sbPrivKey As New Chilkat.StringBuilder
success = sbPrivKey.LoadFile("qa_data/sshKeys/user_ecdsa_key","utf-8")
If (success = False) Then
Debug.WriteLine("Failed to load user_ecdsa_key")
Exit Sub
End If
Dim key As New Chilkat.SshKey
' Provide the password if the user_ecdsa_key is stored in an encrypted format.
key.Password = "secret"
success = key.FromOpenSshPrivateKey(sbPrivKey.GetAsString())
If (success = False) Then
Debug.WriteLine(key.LastErrorText)
Exit Sub
End If
' Indicate that the SSH certificate is to be used for authentication.
' The UseSshCertificate method was added in Chilkat v11.0.0
key.UseSshCertificate(sbSshCert.GetAsString())
Dim ssh As New Chilkat.Ssh
Dim hostname As String = "ssh.example.com"
Dim port As Integer = 22
success = ssh.Connect(hostname,port)
If (success <> True) Then
Debug.WriteLine(ssh.LastErrorText)
Exit Sub
End If
success = ssh.AuthenticatePk("myLogin",key)
If (success <> True) Then
Debug.WriteLine(ssh.LastErrorText)
Exit Sub
End If
Debug.WriteLine("Public-Key Authentication using an SSH Certificate was Successful!")