当前位置: 首页>>代码示例>>PHP>>正文


PHP RSA::loadKey方法代码示例

本文整理汇总了PHP中phpseclib\Crypt\RSA::loadKey方法的典型用法代码示例。如果您正苦于以下问题:PHP RSA::loadKey方法的具体用法?PHP RSA::loadKey怎么用?PHP RSA::loadKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在phpseclib\Crypt\RSA的用法示例。


在下文中一共展示了RSA::loadKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: executeCommand

 /**
  * @param string $commandName
  * @param string $target
  * @param array  $targetConfig
  * @param array  $inputCommand
  * @param array  $userHomeDir
  * @return string
  */
 public function executeCommand($commandName, $target, $targetConfig, $inputCommand, $userHomeDir)
 {
     $remoteCommand = str_replace([sprintf('\'%s\'', $commandName), sprintf('target=\'%s\'', $target)], [$commandName, sprintf('root=%s', $targetConfig['root'])], $inputCommand);
     $remoteCommand = sprintf('%s %s', $targetConfig['console'], $remoteCommand);
     $key = null;
     if (array_key_exists('password', $targetConfig)) {
         $key = $targetConfig['password'];
     }
     if (!$key) {
         $key = new RSA();
         if (array_key_exists('passphrase', $targetConfig['keys'])) {
             $passphrase = $targetConfig['keys']['passphrase'];
             $passphrase = realpath(preg_replace('/~/', $userHomeDir, $passphrase, 1));
             $key->setPassword(trim(file_get_contents($passphrase)));
         }
         $private = $targetConfig['keys']['private'];
         $private = realpath(preg_replace('/~/', $userHomeDir, $private, 1));
         if (!$key->loadKey(trim(file_get_contents($private)))) {
             return $this->getTranslator()->trans('commands.site.debug.messages.private-key');
         }
     }
     $ssh = new SSH2($targetConfig['host'], $targetConfig['port']);
     if (!$ssh->login($targetConfig['user'], $key)) {
         return sprintf('%s - %s', $ssh->getExitStatus(), $ssh->getErrors());
     } else {
         return $ssh->exec($remoteCommand);
     }
 }
开发者ID:ibonelli,项目名称:DrupalConsole,代码行数:36,代码来源:RemoteHelper.php

示例2: factoryAuthentication

 /**
  * @param $config
  * @return NoPasswordAuthentication|PasswordAuthentication|RSAKeyAuthentication|null
  * @throws SSH2Exception
  */
 protected function factoryAuthentication($config)
 {
     $type = $config['type'];
     $username = $config['username'];
     $authentication = null;
     switch ($type) {
         case 'password':
             $password = $config['password'];
             $authentication = new PasswordAuthentication($username, $password);
             break;
         case 'no_password':
             $authentication = new NoPasswordAuthentication($username);
             break;
         case 'rsa':
             $file = $config['file'];
             $keyRSA = new RSA();
             $keyRSA->loadKey(file_get_contents($file));
             $authentication = new RSAKeyAuthentication($username, $keyRSA);
             break;
         case 'rsa_password':
             $file = $config['file'];
             $keyRSA = new RSA();
             $keyRSA->loadKey(file_get_contents($file));
             $password = $config['password'];
             $keyRSA->setPassword($password);
             $authentication = new RSAKeyAuthentication($username, $keyRSA);
             break;
     }
     if (is_null($authentication)) {
         throw new SSH2Exception(sprintf("No authentication for given type '%s'", $type));
     }
     return $authentication;
 }
开发者ID:timitao,项目名称:behatssh2terminalextension,代码行数:38,代码来源:TerminalFactory.php

示例3: login

 /**
  * @return bool
  */
 public function login()
 {
     $password = $this->password;
     $username = $this->username;
     // try to login using ssh key
     if (null === $password) {
         try {
             // try with agent (suppress stupid phpseclib warnings/errors)
             $agent = @new Agent();
         } catch (\Exception $e) {
             $agent = null;
         }
         if ($success = $this->sftp->login($username, $agent)) {
             return true;
         }
         // try with key manually
         $identityFilePath = $_SERVER['HOME'] . '/.ssh/id_rsa';
         if (!is_file($identityFilePath)) {
             $this->io->write(sprintf('Public key file not found in %s', $identityFilePath));
             return false;
         }
         $identityFile = file_get_contents($identityFilePath);
         $key = new RSA();
         $loaded = $key->loadKey($identityFile);
         // first try without keypass
         if (!$loaded || false === ($success = $this->sftp->login($username, $key))) {
             $attempts = 3;
             // now N attempts to load the identity file
             while ($attempts--) {
                 // retry with password
                 $this->keyPassword = $this->keyPassword ?: $this->io->askAndHideAnswer(sprintf('Enter passphrase for %s: ', $identityFilePath));
                 $key->setPassword($this->keyPassword);
                 $loaded = $key->loadKey($identityFile);
                 if (!$loaded) {
                     if ($attempts > 0) {
                         $this->keyPassword = null;
                         $this->io->write('Permission denied, please try again.');
                     }
                 } else {
                     if (false === ($success = $this->sftp->login($username, $key))) {
                         $this->io->write(sprintf('%s@%s: Permission denied (publickey)', $this->username, $this->host));
                     }
                     return $success;
                 }
             }
         }
         return $success;
     }
     // login with given password
     return $this->sftp->login($username, $password);
 }
开发者ID:webcreate,项目名称:conveyor,代码行数:54,代码来源:SftpTransporter.php

示例4: testCrypt

    /**
     * A basic functional test example.
     *
     * @return void
     */
    public function testCrypt()
    {
        $rsa = new RSA();
        $rsa->loadKey('-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDlOJu6TyygqxfWT7eLtGDwajtN
FOb9I5XRb6khyfD1Yt3YiCgQWMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76
xFxdU6jE0NQ+Z+zEdhUTooNRaY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4
gwQco1KRMDSmXSMkDwIDAQAB
-----END PUBLIC KEY-----');
        // public key
        $plaintext = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed gravida felis sit amet nulla accumsan, sed mollis elit tristique. Vivamus fermentum mauris et tellus feugiat luctus. Suspendisse faucibus, orci sed feugiat lobortis, nulla nunc vestibulum nibh, sed vulputate ipsum felis ac nisl. Sed sit amet est a felis posuere mollis eu placerat risus. Mauris eget nisl condimentum, varius sapien vitae, mattis nisl. Nulla porta eu nulla at imperdiet. Integer sollicitudin, ipsum nec tempus rhoncus, ipsum massa elementum sapien, ac malesuada orci augue eu nibh. Quisque posuere porttitor magna id finibus. Nunc porttitor eros et erat semper sagittis. Pellentesque sed luctus sem. Sed vulputate massa mollis lacus tincidunt auctor. Praesent aliquet quis diam sit amet rutrum. Sed mauris sem, placerat sed ex ac, hendrerit lobortis enim. Etiam egestas ex orci. Integer in varius ex, nec scelerisque tortor.';
        //$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_OAEP);
        $ciphertext = $rsa->encrypt($plaintext);
        $rsa->loadKey('-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDlOJu6TyygqxfWT7eLtGDwajtNFOb9I5XRb6khyfD1Yt3YiCgQ
WMNW649887VGJiGr/L5i2osbl8C9+WJTeucF+S76xFxdU6jE0NQ+Z+zEdhUTooNR
aY5nZiu5PgDB0ED/ZKBUSLKL7eibMxZtMlUDHjm4gwQco1KRMDSmXSMkDwIDAQAB
AoGAfY9LpnuWK5Bs50UVep5c93SJdUi82u7yMx4iHFMc/Z2hfenfYEzu+57fI4fv
xTQ//5DbzRR/XKb8ulNv6+CHyPF31xk7YOBfkGI8qjLoq06V+FyBfDSwL8KbLyeH
m7KUZnLNQbk8yGLzB3iYKkRHlmUanQGaNMIJziWOkN+N9dECQQD0ONYRNZeuM8zd
8XJTSdcIX4a3gy3GGCJxOzv16XHxD03GW6UNLmfPwenKu+cdrQeaqEixrCejXdAF
z/7+BSMpAkEA8EaSOeP5Xr3ZrbiKzi6TGMwHMvC7HdJxaBJbVRfApFrE0/mPwmP5
rN7QwjrMY+0+AbXcm8mRQyQ1+IGEembsdwJBAN6az8Rv7QnD/YBvi52POIlRSSIM
V7SwWvSK4WSMnGb1ZBbhgdg57DXaspcwHsFV7hByQ5BvMtIduHcT14ECfcECQATe
aTgjFnqE/lQ22Rk0eGaYO80cc643BXVGafNfd9fcvwBMnk0iGX0XRsOozVt5Azil
psLBYuApa66NcVHJpCECQQDTjI2AQhFc1yRnCU/YgDnSpJVm1nASoRUnU8Jfm3Oz
uku7JUXcVpt08DFSceCEX9unCuMcT72rAQlLpdZir876
-----END RSA PRIVATE KEY-----');
        // private key
        $decryptedText = $rsa->decrypt($ciphertext);
        $this->assertEquals($decryptedText, $plaintext);
    }
开发者ID:avin,项目名称:jsSniffer,代码行数:37,代码来源:CryptTest.php

示例5: testEncryptionModeNone

    public function testEncryptionModeNone()
    {
        $plaintext = 'a';
        $rsa = new RSA();
        $privatekey = '-----BEGIN RSA PRIVATE 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=
-----END RSA PRIVATE KEY-----';
        $rsa->loadKey($privatekey);
        $rsa->loadKey($rsa->getPublicKey());
        $rsa->setEncryptionMode(RSA::ENCRYPTION_NONE);
        $expected = '105b92f59a87a8ad4da52c128b8c99491790ef5a54770119e0819060032fb9e772ed6772828329567f3d7e9472154c1530f8156ba7fd732f52ca1c06' . '5a3f5ed8a96c442e4662e0464c97f133aed31262170201993085a589565d67cc9e727e0d087e3b225c8965203b271e38a499c92fc0d6502297eca712' . '4d04bd467f6f1e7c';
        $expected = pack('H*', $expected);
        $result = $rsa->encrypt($plaintext);
        $this->assertEquals($result, $expected);
        $rsa->loadKey($privatekey);
        $this->assertEquals(trim($rsa->decrypt($result), ""), $plaintext);
    }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:27,代码来源:ModeTest.php

示例6: __construct

 /**
  * Constructor.
  *
  * @param string $username
  * @param Client $client
  *
  * @throws SteamLoginException In case of errors
  */
 public function __construct($username, Client $client)
 {
     $responseBody = Utils::jsonBody($client->post(SteamLogin::STEAMCOMM_WEBSITE . '/login/getrsakey/', array('form_params' => ['donotcache' => Utils::microtime_ms(true), 'username' => $username])));
     $this->publickey_mod = new BigInteger($responseBody->publickey_mod, 16);
     $this->publickey_exp = new BigInteger($responseBody->publickey_exp, 16);
     $this->timestamp = $responseBody->timestamp;
     $this->rsa_key = new RSA();
     $this->rsa_key->setEncryptionMode(RSA::ENCRYPTION_PKCS1);
     $this->rsa_key->loadKey(array('e' => $this->publickey_exp, 'n' => $this->publickey_mod));
 }
开发者ID:drdelay,项目名称:steam-login,代码行数:18,代码来源:SteamRSAKey.php

示例7: onEnable

 public function onEnable()
 {
     $this->saveDefaultConfig();
     $this->saveResource("server-icon.png", false);
     $this->saveResource("steve.yml", false);
     $this->saveResource("alex.yml", false);
     $this->reloadConfig();
     $this->onlineMode = (bool) $this->getConfig()->get("online-mode");
     if ($this->onlineMode and !function_exists("mcrypt_generic_init")) {
         $this->onlineMode = false;
         $this->getLogger()->notice("no mcrypt detected, online-mode has been disabled. Try using the latest PHP binaries");
     }
     if (!$this->getConfig()->exists("motd")) {
         $this->getLogger()->warning("No motd has been set. The server description will be empty.");
         return;
     }
     if (Info::CURRENT_PROTOCOL === 84) {
         $this->translator = new Translator_84();
         $this->rsa = new RSA();
         $this->getServer()->getPluginManager()->registerEvents($this, $this);
         Achievement::add("openInventory", "Taking Inventory");
         //this for DesktopPlayer
         if ($this->onlineMode) {
             $this->getLogger()->info("Server is being started in the background");
             $this->getLogger()->info("Generating keypair");
             $this->rsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
             $this->rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_PKCS1);
             $keys = $this->rsa->createKey(1024);
             $this->privateKey = $keys["privatekey"];
             $this->publicKey = $keys["publickey"];
             $this->rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
             $this->rsa->loadKey($this->privateKey);
         }
         $this->getLogger()->info("Starting Minecraft: PC server on " . ($this->getIp() === "0.0.0.0" ? "*" : $this->getIp()) . ":" . $this->getPort() . " version " . MCInfo::VERSION);
         $disable = true;
         foreach ($this->getServer()->getNetwork()->getInterfaces() as $interface) {
             if ($interface instanceof ProtocolInterface) {
                 $disable = false;
             }
         }
         if ($disable) {
             $this->interface = new ProtocolInterface($this, $this->getServer(), $this->translator);
             $this->getServer()->getNetwork()->registerInterface($this->interface);
         }
     } else {
         $this->getLogger()->critical("Couldn't find a protocol translator for #" . Info::CURRENT_PROTOCOL . ", disabling plugin");
         $this->getPluginLoader()->disablePlugin($this);
     }
 }
开发者ID:iPocketTeam,项目名称:BigBrother,代码行数:49,代码来源:BigBrother.php

示例8: rsa

 private function rsa($public_or_private_key, $padding_mode)
 {
     $rsa = new RSA();
     $rsa->loadKey($public_or_private_key);
     $rsa->setEncryptionMode($padding_mode);
     return $rsa;
 }
开发者ID:jcwatson11,项目名称:jose-php,代码行数:7,代码来源:JWE.php

示例9: connect

 /**
  * Connects to remote server.
  *
  * @throws \InvalidArgumentException|\RuntimeException
  */
 protected function connect()
 {
     $host = $this->gitEnvironment->getHost();
     $username = $this->gitEnvironment->getUsername();
     $port = $this->gitEnvironment->getPort();
     $password = $this->gitEnvironment->getPassword();
     $privateKey = $this->gitEnvironment->getPrivateKey();
     $privateKeyPassword = $this->gitEnvironment->getPrivateKeyPassword();
     $this->sftp = new SFTP($host, 22);
     if (!$this->sftp) {
         throw new SshLoginException(sprintf('SSH connection failed on "%s:%s"', $host, $port));
     }
     if (isset($username) && $privateKey != null) {
         $key = new RSA();
         //Set Private Key Password
         if ($privateKeyPassword) {
             $key->setPassword($privateKeyPassword);
         }
         $key->loadKey($privateKey);
         //Login using private key
         if (!$this->sftp->login($username, $key)) {
             throw new SshLoginException(sprintf('SFTP authentication failed for user "%s" using private key', $username));
         }
     } else {
         if (!$this->sftp->login($username, $password)) {
             throw new SshLoginException(sprintf('SFTP authentication failed for user "%s" using password', $username));
         }
     }
 }
开发者ID:sshversioncontrol,项目名称:git-web-client,代码行数:34,代码来源:SecLibSftpProcess.php

示例10: connect

 /**
  * {@inheritdoc}
  */
 public function connect()
 {
     $this->sftp = new SFTP($this->configuration->getHost(), $this->configuration->getPort());
     switch ($this->configuration->getAuthenticationMethod()) {
         case ServerConfiguration::AUTH_BY_IDENTITY_FILE:
             $key = new RSA();
             $key->loadKey(file_get_contents($this->configuration->getPrivateKey()));
             $result = $this->sftp->login($this->configuration->getUser(), $key);
             break;
         case ServerConfiguration::AUTH_BY_PEM_FILE:
             $key = new RSA();
             $key->loadKey(file_get_contents($this->configuration->getPemFile()));
             $result = $this->sftp->login($this->configuration->getUser(), $key);
             break;
         case ServerConfiguration::AUTH_BY_AGENT:
             $key = new Agent();
             $result = $this->sftp->login($this->configuration->getUser(), $key);
             break;
         default:
             throw new \RuntimeException('You need to specify authentication method.');
     }
     if (!$result) {
         throw new \RuntimeException('Unable to login with the provided credentials.');
     }
 }
开发者ID:simpleci,项目名称:deployer,代码行数:28,代码来源:PhpSecServer.php

示例11: connect

 /**
  *
  */
 public function connect()
 {
     $this->ssh = new SSH2($this->configuration['hostname'], $this->configuration['port']);
     $authenticationMethod = $this->configuration[SftpDriver::CONFIG_AUTHENTICATION_METHOD];
     if (static::AUTHENTICATION_PASSWORD === (int) $authenticationMethod) {
         $authentication = $this->configuration['password'];
     } elseif (static::AUTHENTICATION_PUBKEY === (int) $authenticationMethod) {
         $authentication = new RSA();
         if (!empty($this->configuration['privateKeyPassword'])) {
             $authentication->setPassword($this->configuration['privateKeyPassword']);
         }
         $authentication->loadKey(file_get_contents($this->configuration['privateKey']));
     } else {
         throw new \LogicException('Wrong authentication type for phpseclibAdapter', 1476626149);
     }
     $sshConnected = $this->ssh->login($this->configuration['username'], $authentication);
     if ($sshConnected) {
         $this->sftp = new SFTP($this->configuration['hostname'], $this->configuration['port']);
         $sftpConnected = $this->sftp->login($this->configuration['username'], $authentication);
         if ($sftpConnected) {
             $this->info['userId'] = (int) $this->ssh->exec('echo $EUID');
             $this->info['groupIds'] = GeneralUtility::intExplode(' ', $this->ssh->exec('echo ${GROUPS[*]}'), true);
             return true;
         }
     }
     return false;
 }
开发者ID:vertexvaar,项目名称:falsftp,代码行数:30,代码来源:PhpseclibAdapter.php

示例12: calculateSignature

 /**
  * Static method for quick calls to calculate a signature.
  * @link https://developer.walmartapis.com/#authentication
  * @param string $consumerId
  * @param string $privateKey
  * @param string $requestUrl
  * @param string $requestMethod
  * @param string|null $timestamp
  * @return string
  * @throws \Exception
  */
 public static function calculateSignature($consumerId, $privateKey, $requestUrl, $requestMethod, $timestamp = null)
 {
     if (is_null($timestamp) || !is_numeric($timestamp)) {
         $timestamp = self::getMilliseconds();
     }
     /**
      * Append values into string for signing
      */
     $message = $consumerId . "\n" . $requestUrl . "\n" . strtoupper($requestMethod) . "\n" . $timestamp . "\n";
     /**
      * Get RSA object for signing
      */
     $rsa = new RSA();
     $decodedPrivateKey = base64_decode($privateKey);
     $rsa->setPrivateKeyFormat(RSA::PRIVATE_FORMAT_PKCS8);
     $rsa->setPublicKeyFormat(RSA::PRIVATE_FORMAT_PKCS8);
     /**
      * Load private key
      */
     if ($rsa->loadKey($decodedPrivateKey, RSA::PRIVATE_FORMAT_PKCS8)) {
         /**
          * Make sure we use SHA256 for signing
          */
         $rsa->setHash('sha256');
         $rsa->setSignatureMode(RSA::SIGNATURE_PKCS1);
         $signed = $rsa->sign($message);
         /**
          * Return Base64 Encode generated signature
          */
         return base64_encode($signed);
     } else {
         throw new \Exception("Unable to load private key", 1446780146);
     }
 }
开发者ID:fillup,项目名称:walmart-auth-signature-php,代码行数:45,代码来源:Signature.php

示例13: connect

 /**
  * {@inheritdoc}
  */
 public function connect()
 {
     $serverConfig = $this->getConfiguration();
     $this->sftp = new SFTP($serverConfig->getHost(), $serverConfig->getPort(), 3600);
     switch ($serverConfig->getAuthenticationMethod()) {
         case Configuration::AUTH_BY_PASSWORD:
             $result = $this->sftp->login($serverConfig->getUser(), $serverConfig->getPassword());
             break;
         case Configuration::AUTH_BY_IDENTITY_FILE:
             $key = new RSA();
             $key->setPassword($serverConfig->getPassPhrase());
             $key->loadKey(file_get_contents($serverConfig->getPrivateKey()));
             $result = $this->sftp->login($serverConfig->getUser(), $key);
             break;
         case Configuration::AUTH_BY_PEM_FILE:
             $key = new RSA();
             $key->loadKey(file_get_contents($serverConfig->getPemFile()));
             $result = $this->sftp->login($serverConfig->getUser(), $key);
             break;
         case Configuration::AUTH_BY_AGENT:
             $key = new Agent();
             $key->startSSHForwarding(null);
             $result = $this->sftp->login($serverConfig->getUser(), $key);
             break;
         default:
             throw new RuntimeException('You need to specify authentication method.');
     }
     if (!$result) {
         throw new RuntimeException('Unable to login with the provided credentials.');
     }
 }
开发者ID:acorncom,项目名称:deployer,代码行数:34,代码来源:PhpSecLib.php

示例14: verifyIdToken

 /**
  * Verifies an id token and returns the authenticated apiLoginTicket.
  * Throws an exception if the id token is not valid.
  * The audience parameter can be used to control which id tokens are
  * accepted.  By default, the id token must have been issued to this OAuth2 client.
  *
  * @param $audience
  * @return array the token payload, if successful
  */
 public function verifyIdToken($idToken, $audience = null)
 {
     if (empty($idToken)) {
         throw new LogicException('id_token cannot be null');
     }
     // Check signature
     $certs = $this->getFederatedSignOnCerts();
     foreach ($certs as $cert) {
         $modulus = new BigInteger($this->jwt->urlsafeB64Decode($cert['n']), 256);
         $exponent = new BigInteger($this->jwt->urlsafeB64Decode($cert['e']), 256);
         $rsa = new RSA();
         $rsa->loadKey(array('n' => $modulus, 'e' => $exponent));
         try {
             $payload = $this->jwt->decode($idToken, $rsa->getPublicKey(), array('RS256'));
             if (property_exists($payload, 'aud')) {
                 if ($audience && $payload->aud != $audience) {
                     return false;
                 }
             }
             // support HTTP and HTTPS issuers
             // @see https://developers.google.com/identity/sign-in/web/backend-auth
             $issuers = array(self::OAUTH2_ISSUER, self::OAUTH2_ISSUER_HTTPS);
             if (!isset($payload->iss) || !in_array($payload->iss, $issuers)) {
                 return false;
             }
             return (array) $payload;
         } catch (ExpiredException $e) {
             return false;
         } catch (DomainException $e) {
             // continue
         }
     }
     return false;
 }
开发者ID:andytan2624,项目名称:andytan.net,代码行数:43,代码来源:Verify.php

示例15: execute

 /**
  * {@inheritdoc }
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $privateKeyPath = $input->getOption('privateKey');
     $keyBundlePath = $input->getOption('certificate');
     $path = $input->getOption('path');
     if (is_null($privateKeyPath) || is_null($keyBundlePath) || is_null($path)) {
         $output->writeln('--privateKey, --certificate and --path are required.');
         return null;
     }
     $privateKey = $this->fileAccessHelper->file_get_contents($privateKeyPath);
     $keyBundle = $this->fileAccessHelper->file_get_contents($keyBundlePath);
     if ($privateKey === false) {
         $output->writeln(sprintf('Private key "%s" does not exists.', $privateKeyPath));
         return null;
     }
     if ($keyBundle === false) {
         $output->writeln(sprintf('Certificate "%s" does not exists.', $keyBundlePath));
         return null;
     }
     $rsa = new RSA();
     $rsa->loadKey($privateKey);
     $x509 = new X509();
     $x509->loadX509($keyBundle);
     $x509->setPrivateKey($rsa);
     $this->checker->writeCoreSignature($x509, $rsa, $path);
     $output->writeln('Successfully signed "core"');
 }
开发者ID:rchicoli,项目名称:owncloud-core,代码行数:30,代码来源:SignCore.php


注:本文中的phpseclib\Crypt\RSA::loadKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。