public function testSetPrivate() { $rsa = new RSA(); $key = '-----BEGIN RSA PUBLIC KEY----- MIIBCgKCAQEA61BjmfXGEvWmegnBGSuS+rU9soUg2FnODva32D1AqhwdziwHINFa D1MVlcrYG6XRKfkcxnaXGfFDWHLEvNBSEVCgJjtHAGZIm5GL/KA86KDp/CwDFMSw luowcXwDwoyinmeOY9eKyh6aY72xJh7noLBBq1N0bWi1e2i+83txOCg4yV2oVXhB o8pYEJ8LT3el6Smxol3C1oFMVdwPgc0vTl25XucMcG/ALE/KNY6pqC2AQ6R2ERlV gPiUWOPatVkt7+Bs3h5Ramxh7XjBOXeulmCpGSynXNcpZ/06+vofGi/2MlpQZNhH Ao8eayMp6FcvNucIpUndo1X8dKMv3Y26ZQIDAQAB -----END RSA PUBLIC KEY-----'; $this->assertTrue($rsa->loadKey($key)); $this->assertTrue($rsa->setPrivateKey()); $this->assertGreaterThanOrEqual(1, strlen("{$rsa}")); $this->assertFalse($rsa->getPublicKey()); }
public function login() { $this->connectIfNeeded(false); if ($this->user === null) { throw new FtpException(Yii::t('gsftp', 'Could not login to SFTP server "{host}" on port "{port}" without username.', ['host' => $this->host, 'port' => $this->port])); } else { if ($this->privateKeyFile != null) { $key = new RSA(); if ($this->pass != null && !empty($this->pass)) { $key->setPassword($this->pass); } if ($this->publicKeyFile != null && !empty($this->publicKeyFile)) { $key->setPublicKey(self::_readKeyFile('Public', $this->publicKeyFile)); } $key->setPrivateKey(self::_readKeyFile('Private', $this->privateKeyFile)); if (!$this->handle->login($this->user, $key)) { throw new FtpException(Yii::t('gsftp', 'Could not login to SFTP server "{host}" on port "{port}" with user "{user}" using RSA key.', ['host' => $this->host, 'port' => $this->port, 'user' => $this->user])); } } else { if ($this->pass != null && !empty($this->pass)) { if (!$this->handle->login($this->user, $this->pass)) { throw new FtpException(Yii::t('gsftp', 'Could not login to SFTP server "{host}" on port "{port}" with user "{user}".', ['host' => $this->host, 'port' => $this->port, 'user' => $this->user])); } } } } }