Sample code for 30+ languages & platforms
PowerBuilder

Generate an ed25519 Key and Save in PuTTY Format

See more SSH Examples

Demonstrates generating an ed25519 SSH key and saving it in PuTTY (.ppk) format, both unencrypted and encrypted. Setting the Password property and passing true to ToPuttyPrivateKey produces the encrypted form.

Note: The file paths are relative to the application's current working directory. Supply the paths to your own files.

Background: Ed25519 is the modern default for SSH keys: it offers strong security with very small keys and fast signing, and unlike RSA it has no key-size decision to get wrong. Encrypting the exported private key protects it at rest, so a stolen file is not immediately usable — the trade-off being that the passphrase must be supplied whenever the key is used, which is why unattended jobs often pair an unencrypted key with strict file permissions instead.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Key
integer li_ExportEncrypted
string ls_ExportedKey

li_Success = 0

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

//  Demonstrates generating an ed25519 SSH key and saving it in PuTTY (.ppk) format, both
//  unencrypted and encrypted.

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

li_Success = loo_Key.GenerateEd25519Key()
if li_Success = 0 then
    Write-Debug loo_Key.LastErrorText
    destroy loo_Key
    return
end if

//  A comment may optionally be included in the exported key.
loo_Key.Comment = "This is my new ed25519 key."

//  Export to unencrypted PuTTY format.
li_ExportEncrypted = 0
ls_ExportedKey = loo_Key.ToPuttyPrivateKey(li_ExportEncrypted)
if loo_Key.LastMethodSuccess = 0 then
    Write-Debug loo_Key.LastErrorText
    destroy loo_Key
    return
end if

li_Success = loo_Key.SaveText(ls_ExportedKey,"qa_output/privkey_putty_unencrypted.ppk")
if li_Success = 0 then
    Write-Debug loo_Key.LastErrorText
    destroy loo_Key
    return
end if

//  Export to encrypted PuTTY format.  The passphrase protects the private key at rest and
//  should come from a secure source rather than being hard-coded.
loo_Key.Password = "myKeyPassword"
li_ExportEncrypted = 1
ls_ExportedKey = loo_Key.ToPuttyPrivateKey(li_ExportEncrypted)
if loo_Key.LastMethodSuccess = 0 then
    Write-Debug loo_Key.LastErrorText
    destroy loo_Key
    return
end if

li_Success = loo_Key.SaveText(ls_ExportedKey,"qa_output/privkey_putty_encrypted.ppk")
if li_Success = 0 then
    Write-Debug loo_Key.LastErrorText
    destroy loo_Key
    return
end if

Write-Debug "Success!"


destroy loo_Key