PHP code example of phpseclib / phpseclib2_compat

1. Go to this page and download the library: Download phpseclib/phpseclib2_compat library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phpseclib / phpseclib2_compat example snippets


use phpseclib\Crypt\RSA;

$rsa = new RSA;
$rsa->loadKey('ecdsa private key');

$ssh = new SSH2('website.com');
$ssh->login('username', $rsa);

$methods = [
    'crypt' => array_intersect([
        'arcfour256',
        'arcfour128',
        'aes128-ctr',
        'aes192-ctr',
        'aes256-ctr',
        'twofish128-ctr',
        'twofish192-ctr',
        'twofish256-ctr',
        'aes128-cbc',
        'aes192-cbc',
        'aes256-cbc',
        'twofish128-cbc',
        'twofish192-cbc',
        'twofish256-cbc',
        'twofish-cbc',
        'blowfish-ctr',
        'blowfish-cbc',
        '3des-ctr',
        '3des-cbc'
    ], $ssh->getSupportedEncryptionAlgorithms()),
    'mac' => [
        'hmac-sha2-256',
        'hmac-sha1-96',
        'hmac-sha1',
        'hmac-md5-96',
        'hmac-md5'
    ],
    'comp' => ['none']
];

$ssh->setPreferredAlgorithms([
    'kex' => [
        '[email protected]',
        'diffie-hellman-group-exchange-sha256',
        'diffie-hellman-group-exchange-sha1',
        'diffie-hellman-group14-sha1',
        'diffie-hellman-group14-sha256'
    ],
    'hostkey' => [
        'rsa-sha2-256',
        'rsa-sha2-512',
        'ssh-rsa',
        'ssh-dss'
    ],
    'client_to_server' => $methods,
    'server_to_client' => $methods
]);