コード例 #1
16
ファイル: AriiExec.php プロジェクト: AriiPortal/I5Bundle
 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
2
ファイル: common.php プロジェクト: abcdlzy/webshell-manager
function RSADecrypt($ciphertext, $privateKey)
{
    $rsad = new Crypt_RSA();
    $rsad->loadKey($privateKey);
    $rsad->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
    return $rsad->decrypt(hex2bin($ciphertext));
}
コード例 #3
0
 /**
  * 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
0
ファイル: ThemeDownloader.php プロジェクト: Umz/ImpressPages
 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
0
ファイル: Sftp.php プロジェクト: rudraks/application
 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
0
ファイル: Access.php プロジェクト: romaninsh/dokku_alt
 function generateAndAdd()
 {
     $rsa = new \Crypt_RSA();
     $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_OPENSSH);
     $this->set($rsa->createKey());
     $this->save();
 }
コード例 #7
0
ファイル: Ssh2.class.php プロジェクト: nao-pon/xupdate
 /**
  * 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
0
ファイル: Release.class.php プロジェクト: Warkot/Bolt
 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
0
ファイル: AriiExec.php プロジェクト: AxelANGENAULT/CoreBundle
 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
0
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
0
ファイル: JWE.php プロジェクト: nask0/jose
 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
0
 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
0
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
0
ファイル: PluginDownloader.php プロジェクト: Umz/ImpressPages
 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
0
 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;
 }
コード例 #16
0
 public static function server_connect($sServer, $sAPI = 0)
 {
     $sSSH = new Net_SSH2($sServer->sIPAddress);
     if ($sServer->sPassword == 0) {
         $sKey = new Crypt_RSA();
         $sKey->loadKey(file_get_contents('/var/feathur/data/keys/' . $sServer->sKey));
     } else {
         $sKey = file_get_contents('/var/feathur/data/keys' . $sServer->sKey);
     }
     try {
         if (!$sSSH->login($sServer->sUser, $sKey)) {
             if (!empty($sAPI)) {
                 return $sResult = array("result" => 'Unable to connect to the host node, please contact customer service.');
             }
             echo json_encode(array("result" => 'Unable to connect to the host node, please contact customer service.'));
             die;
         } else {
             $sSSH->setTimeout(30);
             return $sSSH;
         }
     } catch (Exception $e) {
         if (!empty($sAPI)) {
             return $sResult = array("result" => 'Unable to connect to the host node, please contact customer service.');
         }
         echo json_encode(array("result" => 'Unable to connect to the host node, please contact customer service.'));
         die;
     }
 }
コード例 #17
0
ファイル: LoadKeyTest.php プロジェクト: yashb/generator
 public function testRawPKCS1Key()
 {
     $rsa = new Crypt_RSA();
     $key = 'MIICXAIBAAKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUp' . 'wmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ5' . '1s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQABAoGAFijko56+qGyN8M0RVyaRAXz++xTqHBLh' . '3tx4VgMtrQ+WEgCjhoTwo23KMBAuJGSYnRmoBZM3lMfTKevIkAidPExvYCdm5dYq3XToLkkLv5L2' . 'pIIVOFMDG+KESnAFV7l2c+cnzRMW0+b6f8mR1CJzZuxVLL6Q02fvLi55/mbSYxECQQDeAw6fiIQX' . 'GukBI4eMZZt4nscy2o12KyYner3VpoeE+Np2q+Z3pvAMd/aNzQ/W9WaI+NRfcxUJrmfPwIGm63il' . 'AkEAxCL5HQb2bQr4ByorcMWm/hEP2MZzROV73yF41hPsRC9m66KrheO9HPTJuo3/9s5p+sqGxOlF' . 'L0NDt4SkosjgGwJAFklyR1uZ/wPJjj611cdBcztlPdqoxssQGnh85BzCj/u3WqBpE2vjvyyvyI5k' . 'X6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl' . 'U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ' . '37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0=';
     $key = base64_decode($key);
     $this->assertTrue($rsa->loadKey($key));
 }
コード例 #18
0
 function connect()
 {
     $this->link = new Net_SFTP($this->options['hostname'], $this->options['port']);
     if (!$this->keys) {
         if (!$this->link->login($this->options['username'], $this->options['password'])) {
             if ($this->handle_connect_error()) {
                 return false;
             }
             $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)) {
             if ($this->handle_connect_error()) {
                 return false;
             }
             $this->errors->add('auth', sprintf(__('Private key incorrect for %s'), $this->options['username']));
             $this->errors->add('auth', __('Make sure that the key you are using is an RSA key and not a DSA key'));
             return false;
         }
     }
     return true;
 }
コード例 #19
0
ファイル: Services_Signing_Php.php プロジェクト: niel/spotweb
 public function createPrivateKey($sslCnfPath)
 {
     $rsa = new Crypt_RSA();
     $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
     $keyPair = $rsa->createKey();
     return array('public' => $keyPair['publickey'], 'private' => $keyPair['privatekey']);
 }
コード例 #20
0
 protected function createKeys()
 {
     $rsa = new Crypt_RSA();
     $keypair = $rsa->createKey(2048);
     $this['private_key'] = preg_replace("/\r/", "", $keypair['privatekey']);
     $this['public_key'] = preg_replace("/\r/", "", $keypair['publickey']);
 }
コード例 #21
0
ファイル: User.php プロジェクト: Top-Cat/EscrowTF
 private function getEncryptedPassword()
 {
     $key = $this->getRSAKey();
     $rsa = new Crypt_RSA();
     $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
     $rsa->loadKey(['n' => new Math_BigInteger($key->publickey_mod, 16), 'e' => new Math_BigInteger($key->publickey_exp, 16)]);
     return ['code' => base64_encode($rsa->encrypt($this->pass)), 'time' => $key->timestamp];
 }
コード例 #22
0
ファイル: include.php プロジェクト: carlsonsantana/SecureHTML
function descriptografar($texto)
{
    $rsa = new Crypt_RSA();
    $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
    $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
    $rsa->loadKey(file_get_contents('key/rsa_private.pem'));
    return $rsa->decrypt(base64_decode($texto));
}
コード例 #23
0
ファイル: JWK_Test.php プロジェクト: nask0/jose
 function testEncodeWithExtraComponents()
 {
     $rsa = new Crypt_RSA();
     $rsa->loadKey($this->rsa_keys['private']);
     $jwk = JOSE_JWK::encode($rsa, array('kid' => '12345', 'use' => 'sig'));
     $this->assertEquals('12345', $jwk->components['kid']);
     $this->assertEquals('sig', $jwk->components['use']);
 }
コード例 #24
0
ファイル: magicsig.php プロジェクト: pfefferle/google-code
 public function to_string($key)
 {
     $public_key = new Crypt_RSA();
     $public_key->loadKey($key, CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
     $mod = MagicSig::base64_url_encode($public_key->modulus->toBytes());
     $exp = MagicSig::base64_url_encode($public_key->exponent->toBytes());
     return 'RSA.' . $mod . '.' . $exp;
 }
コード例 #25
0
ファイル: crypto.php プロジェクト: EDDA-BA/webEdda
function encryptChallenge($publicKey, $rnd)
{
    $rsa = new Crypt_RSA();
    $rsa->loadKey($publicKey);
    $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
    $ciphertext = $rsa->encrypt($rnd);
    return base64_encode($ciphertext);
}
コード例 #26
0
function decrypt($privatekey, $encrypted)
{
    $rsa = new Crypt_RSA();
    $encrypted = pack('H*', $encrypted);
    $rsa->loadKey($privatekey);
    $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
    return $rsa->decrypt($encrypted);
}
コード例 #27
0
 /**
  * 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);
 }
コード例 #28
0
ファイル: BrSFTP.php プロジェクト: jagermesh/bright
 function connectWithKey($hostName, $userName, $keyFileName, $port = 22, $keyFilePassword = '')
 {
     $key = new Crypt_RSA();
     if ($keyFilePassword) {
         $key->setPassword($keyFilePassword);
     }
     $key->loadKey(file_get_contents($keyFileName));
     $this->connect($hostName, $userName, $key, $port);
 }
コード例 #29
0
ファイル: Rsa.php プロジェクト: sayiho/Jumper
 /**
  * @return RsaKey the rsa key
  */
 public function getAuthentication()
 {
     $key = new RsaKey();
     $key->loadKey(file_get_contents($this->key));
     if (!is_null($this->password)) {
         $key->setPassword($this->password);
     }
     return $key;
 }
コード例 #30
-1
 private function testKeys($params)
 {
     $str = 'test string';
     if (!function_exists('openssl_public_decrypt')) {
         // зашифруем строку
         openssl_private_encrypt($str, $sign, $params['private']);
         // проверим подпись
         openssl_public_decrypt($sign, $str2, $params['public']);
         $ret = $str == $str2;
     } else {
         set_include_path(get_include_path() . PATH_SEPARATOR . WPAdm_Core::getPluginDir() . '/modules/phpseclib');
         require_once 'Crypt/RSA.php';
         // зашифруем строку
         define('CRYPT_RSA_PKCS15_COMPAT', true);
         $rsa = new Crypt_RSA();
         $rsa->loadKey($params['private']);
         $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
         $ciphertext = $rsa->encrypt($str);
         // проверим подпись
         $rsa = new Crypt_RSA();
         $rsa->loadKey($params['public']);
         $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
         $ret = $str == $rsa->decrypt($ciphertext);
     }
     $this->result->setResult(WPAdm_result::WPADM_RESULT_SUCCESS);
     $this->result->setData(array('match' => (int) $ret));
 }