我必须连接到 SFTP 服务器。我首先使用了这段代码:
$Key = new RSA();
$Key->setPassword("password");
$Key->loadKey(file_get_contents('path_to_RSA_private_key'));
$sftp = new SFTP($IP_addr, $port_number);
if (!$sftp->login('username', $Key))
echo date('Y/m/d H:i:s').' SFTP login failed to $IP_addr';
它运作良好。我知道 phpseclib 使用默认的 sha1,我想使用 sha256。所以我尝试使用该代码:
$Key = new RSA();
$Key->setHash('sha256');
$Key->setMGFHash('sha256');
$Key->setPassword("password");
$Key->loadKey(file_get_contents('path_to_RSA_private_key'));
$sftp = new SFTP($IP_addr, $port_number);
if (!$sftp->login('username', $Key))
echo date('Y/m/d H:i:s').' SFTP login failed to $IP_addr';
但它不起作用。我在服务器上收到了这条消息:
error: key_verify: invalid format
如有必要,我可以在服务器端发送调试日志。此服务器使用密码、KexAlgorithms 和 MACs 参数的默认值。
感谢帮助。