本文整理汇总了PHP中Crypt_RSA::loadKey方法的典型用法代码示例。如果您正苦于以下问题:PHP Crypt_RSA::loadKey方法的具体用法?PHP Crypt_RSA::loadKey怎么用?PHP Crypt_RSA::loadKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Crypt_RSA
的用法示例。
在下文中一共展示了Crypt_RSA::loadKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Exec
public function Exec($command)
{
$engine = $this->session->getSpooler();
if (!isset($engine[0]['shell'])) {
print "?!";
exit;
}
$shell = $engine[0]['shell'];
$host = $shell['host'];
$user = $shell['user'];
$password = $shell['password'];
$method = 'CURL';
set_include_path(get_include_path() . PATH_SEPARATOR . '../vendor/phpseclib');
include 'Net/SSH2.php';
include 'Crypt/RSA.php';
$ssh = new \Net_SSH2($host);
if (1) {
$key = new \Crypt_RSA();
$ret = $key->loadKey("-----BEGIN RSA PRIVATE KEY-----\nMIICWgIBAAKBgQCzRy01HoHIzBJJb/D8A/eTV3qiZxy0NIR97NE14rJblnJZT5Kg\noP2DvIRzlB0msL5cHQJ/qXYAoemHRDKqNZuj89+MYsBeZqNu3/DXdZLq9XJ8e2rb\nsGrDjHvCHEDWL0JIRFnRacem55+XsUsKTIs4tbcD6adMPIYJSQQ7oB/8AQIBIwKB\ngB67vptkUMNWLwVGY9NuZPSv6SMnnoVK1OJjHIzlCKH8iKGYnMsUSLd/ZynBnpjr\nGVGekrbMl+LZ7YTnHqDV/WxGoWEc3xiHE8/HwZwQZxP92K70inz8+6dGEagsrSqO\nQkdAPR/+qen7uQ9yXqj7WAoNFicPJ2cpo8kuEW33KywzAkEA4yH4jf0uNBFDUkR6\ni9DQC5bsgEloVezWnCsm6eIm5o5SGKPZ6Rpro/h3pq5qvPmCtjrZFnK0Dab9xkFr\n/F9lkwJBAMoQMqxYdnPz74Bto99o0PZrk2ikROwXR9eURi3B4bWGq9+mvN3OEQdE\n8JofGyq60LMlnFAkE7v49fYHziyaFJsCQHTPpGZHsVybKe/LcjlG0WULyhYXH7cp\nWG2SiQqRkFlQgf4LH5xz/Nf8IEcX3x9bv5DrEI8zrQ5V4Zko9bT93HcCQQCEyNDX\np9jP2tCWOWuwEa3jwwkY4PoXfQNTJuxJ9G/AbnDyDnwcup15zje1vKtz2dmaS+pg\njLyC1s2Ea4d8ZUC9AkAeUr/N+011K2zGTjxZnAFY/Ow348bomzddiJYAYA+76exV\n3wUYsjeDxqq8Km93+iMQ8DDNZIvoVcfYQW9BfDlf\n-----END RSA PRIVATE KEY----- ");
if (!$ret) {
echo "loadKey failed\n";
print "<pre>" . $ssh->getLog() . '</pre>';
exit;
}
} elseif (isset($shell['password'])) {
$key = $shell['password'];
} else {
$key = '';
// ?! possible ?
}
if (!$ssh->login($user, $key)) {
exit("Login Failed ({$user})");
}
return $ssh->exec("system '{$command}'");
}
示例2: RSADecrypt
function RSADecrypt($ciphertext, $privateKey)
{
$rsad = new Crypt_RSA();
$rsad->loadKey($privateKey);
$rsad->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
return $rsad->decrypt(hex2bin($ciphertext));
}
示例3: CryptRSA
/**
* @return \Crypt_RSA|null
*/
public static function CryptRSA()
{
if (null === \RainLoop\Utils::$RSA) {
if (!\defined('_phpseclib_')) {
\set_include_path(\get_include_path() . PATH_SEPARATOR . APP_VERSION_ROOT_PATH . 'app/libraries/phpseclib');
define('_phpseclib_', true);
}
if (!\class_exists('Crypt_RSA', false)) {
include_once 'Crypt/RSA.php';
\defined('CRYPT_RSA_MODE') || \define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_INTERNAL);
}
if (\class_exists('Crypt_RSA')) {
$oRsa = new \Crypt_RSA();
$oRsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$oRsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
$oRsa->setPrivateKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_PKCS1);
$sPrivateKey = \file_exists(APP_PRIVATE_DATA . 'rsa/private') ? \file_get_contents(APP_PRIVATE_DATA . 'rsa/private') : '';
if (!empty($sPrivateKey)) {
$oRsa->loadKey($sPrivateKey, CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
$oRsa->loadKey($oRsa->getPublicKey(), CRYPT_RSA_PUBLIC_FORMAT_PKCS1);
\RainLoop\Utils::$RSA = $oRsa;
}
}
}
return \RainLoop\Utils::$RSA;
}
示例4: isValidKey
/**
* Return true if $pub_k and $pri_k encode and decode the same text
*
* @param String $pub_k
* @param String $pri_k
* @return boolean
*/
static function isValidKey($pub_k, $pri_k)
{
$plaintext = 'pippopippo';
$rsa = new Crypt_RSA();
$rsa->loadKey($pub_k);
$ciphertext = $rsa->encrypt($plaintext);
$rsa->loadKey($pri_k);
return $plaintext == $rsa->decrypt($ciphertext);
}
示例5: decrypt
function decrypt($cipher)
{
if ($this->hasKeys() == false) {
return "";
}
$keys = $this->getKeys();
$rsa = new Crypt_RSA();
$rsa->loadKey($keys->publickey);
$rsa->loadKey($keys->privatekey);
return $rsa->decrypt($cipher);
}
示例6: initRsa
protected function initRsa($publicKeyFile)
{
if (!file_exists($publicKeyFile) || !is_readable($publicKeyFile)) {
throw new \Exception('Public key file does not exist or is not readable.');
}
$public_key = file_get_contents($publicKeyFile);
$this->rsa = new \Crypt_RSA();
$x509 = new \File_X509();
$x509->loadX509($public_key);
$this->rsa->loadKey($x509->getPublicKey());
$this->rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$this->rsa->setHash('sha1');
}
示例7: __construct
/**
* @param string $pem_format
* @param string $password
* @throws RSABadPEMFormat
*/
public function __construct($pem_format, $password = null)
{
$this->pem_format = $pem_format;
$this->rsa_imp = new \Crypt_RSA();
if (!empty($password)) {
$this->rsa_imp->setPassword($password);
}
$res = $this->rsa_imp->loadKey($this->pem_format, CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
if (!$res) {
throw new RSABadPEMFormat(sprintf('pem %s', $pem_format));
}
$this->n = $this->rsa_imp->modulus;
}
示例8: downloadTheme
public function downloadTheme($name, $url, $signature)
{
$model = Model::instance();
//download theme
$net = new \Ip\Internal\NetHelper();
$themeTempFilename = $net->downloadFile($url, ipFile('file/secure/tmp/'), $name . '.zip');
if (!$themeTempFilename) {
throw new \Ip\Exception('Theme file download failed.');
}
$archivePath = ipFile('file/secure/tmp/' . $themeTempFilename);
//check signature
$fileMd5 = md5_file($archivePath);
$rsa = new \Crypt_RSA();
$rsa->loadKey($this->publicKey);
$rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
$verified = $rsa->verify($fileMd5, base64_decode($signature));
if (!$verified) {
throw new \Ip\Exception('Theme signature verification failed.');
}
//extract
$helper = Helper::instance();
$secureTmpDir = ipFile('file/secure/tmp/');
$tmpExtractedDir = \Ip\Internal\File\Functions::genUnoccupiedName($name, $secureTmpDir);
\Ip\Internal\Helper\Zip::extract($secureTmpDir . $themeTempFilename, $secureTmpDir . $tmpExtractedDir);
unlink($archivePath);
//install
$extractedDir = $helper->getFirstDir($secureTmpDir . $tmpExtractedDir);
$installDir = $model->getThemeInstallDir();
$newThemeDir = \Ip\Internal\File\Functions::genUnoccupiedName($name, $installDir);
rename($secureTmpDir . $tmpExtractedDir . '/' . $extractedDir, $installDir . $newThemeDir);
}
示例9: app_login
/**
* app_login
*
* @param string $server
*
* @return bool
**/
public function app_login($server)
{
$ftp_id = $this->mod_config['FTP_UserName'];
$ftp_pass = $this->mod_config['FTP_password'];
// LOGIN
// @define('NET_SFTP_LOGGING', NET_SFTP_LOG_COMPLEX);
@define('NET_SFTP_LOGGING', NET_SFTP_LOG_SIMPLE);
$this->Verbose = TRUE;
//TRUE or FALSE
$this->LocalEcho = FALSE;
//$this->Passive(TRUE);
$key = new Crypt_RSA();
$key->setPassword($ftp_pass);
$key->loadKey($this->mod_config['SSH_key']);
$port = (int) $this->mod_config['SSH_port'];
//phpseclib
$this->sftp = new Net_SFTP($server, $port);
if (!$this->sftp->login($ftp_id, $key)) {
$this->mes .= "SSH Login Failed<br />\n";
$this->mes .= $this->getSSH2Errors();
return false;
}
$this->mes .= "PWD:" . $this->sftp->pwd() . "<br />\n";
$this->mes .= $this->getSSH2Log();
return true;
}
示例10: deploy
public function deploy()
{
$releaseId = $this->dataBase->startRelease();
$ssh = new Net_SSH2(SSH_SERVER);
$key = new Crypt_RSA();
$key->setPassword(SSH_PASSWORD);
$key->loadKey(file_get_contents(PATH_TO_PRIVATE_KEY));
if (!$ssh->login(SSH_LOGIN, $key)) {
$this->dataBase->logStep($releaseId, 'ssh ' . SSH_SERVER, ['error' => 'Login failed'], 1);
exit('Login Failed');
}
$ssh->enableQuietMode();
$command = $this->bash->dtLock('sandbox-mercury', 'mercury');
$output['success'] = $ssh->exec($command);
$output['error'] = $ssh->getStdError();
$this->dataBase->logStep($releaseId, $command, $output, $ssh->getExitStatus());
$command = $this->bash->dtPrep('sandbox-mercury', 'mercury', ["mercury" => "dev"]);
$output['success'] = $ssh->exec($command);
$output['error'] = $ssh->getStdError();
$this->dataBase->logStep($releaseId, $command, $output, $ssh->getExitStatus());
$command = $this->bash->dtPush('sandbox-mercury', 'mercury');
$output['success'] = $ssh->exec($command);
$output['error'] = $ssh->getStdError();
$this->dataBase->logStep($releaseId, $command, $output, $ssh->getExitStatus());
}
示例11: Exec
public function Exec($shell, $command, $stdin = '')
{
$host = $shell['host'];
$user = $shell['user'];
$ssh = new \Net_SSH2($host);
if (isset($shell['key'])) {
$key = new \Crypt_RSA();
$ret = $key->loadKey($shell['key']);
if (!$ret) {
$this->status = '!KEY';
echo "loadKey failed\n";
print "<pre>" . $ssh->getLog() . '</pre>';
return;
}
} elseif (isset($shell['password'])) {
$key = $shell['password'];
} else {
$key = '';
// ?! possible ?
}
if (!@$ssh->login($shell['user'], $key)) {
$this->status = '!LOGIN';
print 'Login Failed: ' . $shell['user'];
print "<pre>" . $ssh->getLog() . '</pre>';
return;
}
$this->status = 'RUNNING';
if ($stdin == '') {
return $ssh->exec("{$command}");
}
return;
}
示例12: signNewCert
function signNewCert()
{
if (!$GLOBALS['isCA']) {
return false;
} else {
$CAPrivKey = new Crypt_RSA();
$CAPrivKey->loadKey($GLOBALS['CAPrivKeyStr']);
$CAx509 = new File_X509();
$CAx509->loadX509($GLOBALS['CAPubX509']);
//认证证书
$privKey = new Crypt_RSA();
$keyArray = $CAPrivKey->createKey($GLOBALS['RSALength']);
$privKey->loadKey($keyArray['privatekey']);
$pubKey = new Crypt_RSA();
$pubKey->loadKey($keyArray['publickey']);
$pubKey->setPublicKey();
$subject = new File_X509();
$subject->setDNProp('id-at-organizationName', $GLOBALS['CAname'] . ' cert');
$subject->setPublicKey($pubKey);
$issuer = new File_X509();
$issuer->setPrivateKey($CAPrivKey);
$issuer->setDN($CAx509->getDN());
$x509 = new File_X509();
$result = $x509->sign($issuer, $subject);
return array('privateKey' => $privKey->getPrivateKey(), 'publicX509' => $x509->saveX509($result));
}
}
示例13: rsa
private function rsa($public_or_private_key, $padding_mode)
{
$rsa = new Crypt_RSA();
$rsa->loadKey($public_or_private_key);
$rsa->setEncryptionMode($padding_mode);
return $rsa;
}
示例14: fetchOpenIdConfig
protected function fetchOpenIdConfig()
{
try {
$apiClient = $this->getApiClient();
$config = $apiClient->get('.well-known/openid-configuration');
$jwkRes = $apiClient->get($config->jwks_uri);
$jwks = $jwkRes->keys;
$keys = [];
$rsa = new \Crypt_RSA();
foreach ($jwks as $key) {
//if x509 key is available, we don't need to generate it below.
if (!empty($key->x_509)) {
$keys[$key->kid] = $key->x_509;
continue;
}
$public = '<RSAKeyValue>
<Modulus>' . $this->base64_from_url($key->n) . '</Modulus>
<Exponent>' . $this->base64_from_url($key->e) . '</Exponent>
</RSAKeyValue>';
$rsa->loadKey($public, CRYPT_RSA_PUBLIC_FORMAT_XML);
$rsa->setPublicKey();
$keys[$key->kid] = $rsa->getPublicKey();
}
$config->keys = $keys;
return $config;
} catch (SSO\Exception\HttpException $e) {
throw new OpenIdConfigurationException('OpenID configuration can not be fetched', 0, $e);
}
}
示例15: downloadPlugin
public function downloadPlugin($name, $url, $signature)
{
if (is_dir(ipFile("Plugin/{$name}/"))) {
Service::deactivatePlugin($name);
Helper::removeDir(ipFile("Plugin/{$name}/"));
}
//download plugin
$net = new \Ip\Internal\NetHelper();
$pluginTempFilename = $net->downloadFile($url, ipFile('file/secure/tmp/'), $name . '.zip');
if (!$pluginTempFilename) {
throw new \Ip\Exception('Plugin file download failed.');
}
$archivePath = ipFile('file/secure/tmp/' . $pluginTempFilename);
//check signature
$fileMd5 = md5_file($archivePath);
$rsa = new \Crypt_RSA();
$rsa->loadKey($this->publicKey);
$rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
$verified = $rsa->verify($fileMd5, base64_decode($signature));
if (!$verified) {
throw new \Ip\Exception('Plugin signature verification failed.');
}
//extract
$secureTmpDir = ipFile('file/secure/tmp/');
$tmpExtractedDir = \Ip\Internal\File\Functions::genUnoccupiedName($name, $secureTmpDir);
\Ip\Internal\Helper\Zip::extract($secureTmpDir . $pluginTempFilename, $secureTmpDir . $tmpExtractedDir);
unlink($archivePath);
//install
$extractedDir = $this->getFirstDir($secureTmpDir . $tmpExtractedDir);
$installDir = Model::pluginInstallDir();
$newPluginDir = \Ip\Internal\File\Functions::genUnoccupiedName($name, $installDir);
rename($secureTmpDir . $tmpExtractedDir . '/' . $extractedDir, $installDir . $newPluginDir);
Service::activatePlugin($name);
}