Sample code for 30+ languages & platforms
Visual Basic 6.0

SSH Tunnel Credentials from OS Secure Storage

See more SSH Tunnel Examples

Demonstrates the EnableSecrets property, which enables automatic resolution of credentials from the operating system's secure storage. When enabled, password properties and methods may receive a "secret specification string" beginning with !! instead of a literal password.

Background: This is a cleaner alternative to reading a secret yourself and passing it in: with EnableSecrets on, you hand Chilkat a reference like !!my_secret_name and it fetches the actual value from the platform's secure store — Windows Credential Manager, Apple Keychain, and so on. The literal password never appears in your source or configuration, which is exactly the practice recommended throughout these examples.

Chilkat Visual Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

'  Demonstrates the SshTunnel.EnableSecrets property, which enables automatic resolution of
'  credentials from the operating system's secure storage.

Dim tunnel As New ChilkatSshTunnel

'  When EnableSecrets is 1, supported password properties and methods may receive a "secret
'  specification string" beginning with "!!" instead of a literal password.  Chilkat resolves the
'  secret from the OS secure store (Windows Credential Manager, Apple Keychain, etc.).
tunnel.EnableSecrets = 1

tunnel.DestHostname = "db.internal.example.com"
tunnel.DestPort = 5432

Dim sshPort As Long
sshPort = 22
success = tunnel.Connect("ssh.example.com",sshPort)
If (success = 0) Then
    Debug.Print tunnel.LastErrorText
    Exit Sub
End If

'  Pass a secret specification instead of a literal password.  Chilkat looks up the named secret
'  in the OS secure store rather than using this text directly.
Dim password As String
password = "!!my_ssh_password_secret"
success = tunnel.AuthenticatePw("mySshLogin",password)
If (success = 0) Then
    Debug.Print tunnel.LastErrorText
    Exit Sub
End If

Dim listenPort As Long
listenPort = 1080
success = tunnel.BeginAccepting(listenPort)
If (success = 0) Then
    Debug.Print tunnel.LastErrorText
    Exit Sub
End If

Debug.Print "Authenticated using a secret from OS secure storage."

Dim waitForThreadExit As Long
waitForThreadExit = 1
success = tunnel.CloseTunnel(waitForThreadExit)
If (success = 0) Then
    Debug.Print tunnel.LastErrorText
    Exit Sub
End If