PowerBuilder
PowerBuilder
Initiate an SSH Key Re-Exchange
See more SSH Examples
Demonstrates the Chilkat Ssh.ReKey method, which initiates an SSH key re-exchange and waits for it to complete. It takes no arguments. Either the client or the server may trigger rekeying at any time.
Background: Rekeying periodically replaces the session keys to limit how much data is protected by any single key. RFC 4253 recommends it after roughly one gigabyte of transfer or one hour, whichever comes first. In practice servers initiate this automatically and Chilkat handles it transparently, so calling
ReKey explicitly is rarely necessary.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Ssh
integer li_SshPort
string ls_Password
li_Success = 0
// Demonstrates the Ssh.ReKey method, which initiates an SSH key re-exchange and waits for it to
// complete. It takes no arguments. In normal use the server initiates rekeying as needed and
// Chilkat handles it transparently.
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
// Normally you would not hard-code the password in source. You should instead obtain it
// from an interactive prompt, environment variable, or a secrets vault.
ls_Password = "mySshPassword"
li_Success = loo_Ssh.AuthenticatePw("mySshLogin",ls_Password)
if li_Success = 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
// Explicitly initiate a key re-exchange on the live connection.
li_Success = loo_Ssh.ReKey()
if li_Success = 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
Write-Debug "Key re-exchange complete."
loo_Ssh.Disconnect()
destroy loo_Ssh