phpopensslputtyprivate-key

PHP / Bash: Creating PPK out of OpenSSH Key with passphrase


I would like to create a php script that creates keys for ssh-authentication. I've started with a

exec("ssh-keygen -b 1024 -t dsa -N *pwd* -f *path-to-file* -q");

to create the private and public-key-pair. No problem till here ;)

Now I've to convert the OpenSSL-Key to the ppk-format of PuTTY (in the cmd, not in the GUI). If anyone have an Idea on how to manage that, please let me know.

Thanks


Solution

  • If you were working with RSA keys you could do this (requires phpseclib):

    <?php
    include('Crypt/RSA.php');
    
    $rsa = new Crypt_RSA();
    $rsa->setPassword('password');
    $rsa->loadKey('...');
    
    //$rsa->setPassword(); // clear the password if there was one
    echo $rsa->getPrivateKey(CRYPT_RSA_PRIVATE_FORMAT_PUTTY);
    ?>