本文整理汇总了PHP中Crypt_RSA类的典型用法代码示例。如果您正苦于以下问题:PHP Crypt_RSA类的具体用法?PHP Crypt_RSA怎么用?PHP Crypt_RSA使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Crypt_RSA类的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: login
/**
* Log user in
*/
function login()
{
$params = $this->request->get('params', false);
if ($params) {
$rsa = new Crypt_RSA();
$my_pub_key = ConfigOptions::getValue('frosso_auth_my_pub_key');
$my_pri_key = ConfigOptions::getValue('frosso_auth_my_pri_key');
$rsa->loadKey($my_pri_key);
$decrypted_params = $rsa->decrypt($params);
if ($decrypted_params) {
list($email, $token, $timestamp) = explode(';', $decrypted_params);
if ($email && $token && $timestamp) {
if ($token == ConfigOptions::getValue('frosso_auth_my_pri_token') && time() - 60 * 10 < $timestamp && $timestamp < time() + 60 * 10) {
Authentication::useProvider('FrossoProvider', false);
Authentication::getProvider()->initialize(array('sid_prefix' => AngieApplication::getName(), 'secret_key' => AngieApplication::getAdapter()->getUniqueKey()));
Authentication::getProvider()->authenticate($email);
} else {
$this->response->forbidden();
}
// token non valido
} else {
$this->response->badRequest(array('message' => 'Parametri non '));
}
// parametri non validi
} else {
$this->response->badRequest(array('message' => 'Parametri non validi'));
}
} else {
$this->response->badRequest(array('message' => 'Parametri non settati'));
}
// parametri non settati
}
示例4: 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);
}
示例5: connect
public function connect($test = false)
{
if (!$this->connection or $test) {
$server = $this->server;
require_once 'Crypt/RSA.php';
require_once 'Net/SFTP.php';
$this->connection = new \Net_SFTP($server['host'], $server['port'], 10);
$logged_in = false;
if (isset($server['sftp_key'])) {
$key = new \Crypt_RSA();
if (isset($server['pass']) && !empty($server['pass'])) {
$key->setPassword($server['pass']);
}
$key->loadKey(file_get_contents($server['sftp_key']));
$logged_in = $this->connection->login($server['user'], $key);
if (!$logged_in) {
Helpers::error("Could not login to {$this->host}. It may be because the key requires a passphrase, which you need to specify it as the 'pass' attribute.");
}
} else {
$logged_in = $this->connection->login($server['user'], $server['pass']);
if (!$logged_in) {
Helpers::error("Could not login to {$this->host}");
}
}
if (!$this->connection->chdir($server['path'])) {
Helpers::error("Could not change the directory to {$server['path']} on {$this->host}");
}
Helpers::logmessage("Connected to: {$this->host}");
$this->current_commit = $this->get_file('REVISION', true);
}
if ($test) {
$this->disconnect();
}
}
示例6: generateAndAdd
function generateAndAdd()
{
$rsa = new \Crypt_RSA();
$rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_OPENSSH);
$this->set($rsa->createKey());
$this->save();
}
示例7: 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;
}
示例8: 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());
}
示例9: 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;
}
示例10: 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));
}
}
示例11: 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;
}
示例12: 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);
}
}
示例13: _google_verify_token
function _google_verify_token($public_key, $signature, $signed_data, $sku, $base_url)
{
$comments = array();
$error = '';
$status = 'unknown';
if (!class_exists('Crypt_RSA')) {
$comments[] = 'PHPSecLib is not in the PHP path.';
}
$purchaseToken = _google_get_product_id($signed_data, $sku);
if (empty($purchaseToken)) {
$status = 'invalid';
$error = 'The SKU is not present in the data.';
} else {
$status = 'unverified';
// unverified until verified
$comments[] = 'The SKU is present in the data.';
$comments[] = 'The purchase token is ' . str_replace("--", "-\n-", $purchaseToken);
// Split any --'s otherwise XML is not well-formed
// verify the data signature
if (!class_exists('Crypt_RSA')) {
$error = 'PHPSecLib is not in the PHP path.';
} else {
$rsa = new Crypt_RSA();
$rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
$rsa->loadKey("-----BEGIN PUBLIC KEY-----\n" . $public_key . "\n-----END PUBLIC KEY-----");
if ($rsa->verify($signed_data, base64_decode($signature))) {
$comments[] = 'verified ok';
$status = 'OK';
} else {
$comments[] = 'verification failed';
}
}
}
return array('status' => $status, 'comments' => $comments, 'error' => $error);
}
示例14: 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);
}
示例15: connect
function connect()
{
$this->link = new Net_SFTP($this->options['hostname'], $this->options['port']);
if (!$this->link) {
$this->errors->add('connect', sprintf(__('Failed to connect to SSH2 Server %1$s:%2$s'), $this->options['hostname'], $this->options['port']));
return false;
}
if (!$this->keys) {
if (!$this->link->login($this->options['username'], $this->options['password'])) {
$this->errors->add('auth', sprintf(__('Username/Password incorrect for %s'), $this->options['username']));
return false;
}
} else {
$rsa = new Crypt_RSA();
if ($this->password) {
$rsa->setPassword($this->options['password']);
}
$rsa->loadKey($this->options['private_key']);
if (!$this->link->login($this->options['username'], $rsa)) {
$this->errors->add('auth', sprintf(__('Private key incorrect for %s'), $this->options['username']));
return false;
}
}
return true;
}