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


PHP RSA::setPublicKey方法代码示例

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


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

示例1: testSaveNullRSAParam

    /**
     * @group github705
     */
    public function testSaveNullRSAParam()
    {
        $privKey = new RSA();
        $privKey->loadKey('-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDMswfEpAgnUDWA74zZw5XcPsWh1ly1Vk99tsqwoFDkLF7jvXy1
dDLHYfuquvfxCgcp8k/4fQhx4ubR8bbGgEq9B05YRnViK0R0iBB5Ui4IaxWYYhKE
8xqAEH2fL+/7nsqqNFKkEN9KeFwc7WbMY49U2adlMrpBdRjk1DqIEW3QTwIDAQAB
AoGBAJ+83cT/1DUJjJcPWLTeweVbPtJp+3Ku5d1OdaGbmURVs764scbP5Ihe2AuF
V9LLZoe/RdS9jYeB72nJ3D3PA4JVYYgqMOnJ8nlUMNQ+p0yGl5TqQk6EKLI8MbX5
kQEazNqFXsiWVQXubAd5wjtb6g0n0KD3zoT/pWLES7dtUFexAkEA89h5+vbIIl2P
H/NnkPie2NWYDZ1YiMGHFYxPDwsd9KCZMSbrLwAhPg9bPgqIeVNfpwxrzeksS6D9
P98tJt335QJBANbnCe+LhDSrkpHMy9aOG2IdbLGG63MSRUCPz8v2gKPq3kYXDxq6
Y1iqF8N5g0k5iirHD2qlWV5Q+nuGvFTafCMCQQC1wQiC0IkyXEw/Q31RqI82Dlcs
5rhEDwQyQof3LZEhcsdcxKaOPOmKSYX4A3/f9w4YBIEiVQfoQ1Ig1qfgDZklAkAT
TQDJcOBY0qgBTEFqbazr7PScJR/0X8m0eLYS/XqkPi3kYaHLpr3RcsVbmwg9hVtx
aBtsWpliLSex/HHhtRW9AkBGcq67zKmEpJ9kXcYLEjJii3flFS+Ct/rNm+Hhm1l7
4vca9v/F2hGVJuHIMJ8mguwYlNYzh2NqoIDJTtgOkBmt
-----END RSA PRIVATE KEY-----');
        $pubKey = new RSA();
        $pubKey->loadKey($privKey->getPublicKey());
        $pubKey->setPublicKey();
        $subject = new X509();
        $subject->setDNProp('id-at-organizationName', 'phpseclib demo cert');
        $subject->setPublicKey($pubKey);
        $issuer = new X509();
        $issuer->setPrivateKey($privKey);
        $issuer->setDN($subject->getDN());
        $x509 = new X509();
        $result = $x509->sign($issuer, $subject);
        $cert = $x509->saveX509($result);
        $cert = $x509->loadX509($cert);
        $this->assertArrayHasKey('parameters', $cert['tbsCertificate']['subjectPublicKeyInfo']['algorithm']);
        $this->assertArrayHasKey('parameters', $cert['signatureAlgorithm']);
        $this->assertArrayHasKey('parameters', $cert['tbsCertificate']['signature']);
    }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:38,代码来源:X509Test.php

示例2: getPublicKey

    /**
     * Gets the public key
     *
     * Returns a \phpseclib\Crypt\RSA object or a false.
     *
     * @access public
     * @return mixed
     */
    function getPublicKey()
    {
        if (isset($this->publicKey)) {
            return $this->publicKey;
        }

        if (isset($this->currentCert) && is_array($this->currentCert)) {
            foreach (array('tbsCertificate/subjectPublicKeyInfo', 'certificationRequestInfo/subjectPKInfo') as $path) {
                $keyinfo = $this->_subArray($this->currentCert, $path);
                if (!empty($keyinfo)) {
                    break;
                }
            }
        }
        if (empty($keyinfo)) {
            return false;
        }

        $key = $keyinfo['subjectPublicKey'];

        switch ($keyinfo['algorithm']['algorithm']) {
            case 'rsaEncryption':
                $publicKey = new RSA();
                $publicKey->loadKey($key);
                $publicKey->setPublicKey();
                break;
            default:
                return false;
        }

        return $publicKey;
    }
开发者ID:juggernautsei,项目名称:openemr,代码行数:40,代码来源:X509.php

示例3: setPublicKey

 /**
  * Set Public Key
  *
  * Called by \phpseclib\System\SSH\Agent::requestIdentities()
  *
  * @param \phpseclib\Crypt\RSA $key
  * @access private
  */
 function setPublicKey($key)
 {
     $this->key = $key;
     $this->key->setPublicKey();
 }
开发者ID:bitking,项目名称:sysPass,代码行数:13,代码来源:Identity.php

示例4: testSignedPKCS1

    /**
     * @group github468
     */
    public function testSignedPKCS1()
    {
        $rsa = new RSA();
        $key = '-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC/k7FwSDE9R9rvTU2nGdJwKaVG
RvBIYGJNahseQhZkQH4CVFMdpWhmD8PyXpjNHtV1CJ0bqAX6e5QyNjvl0FeBj9dz
JWrQdxx/WNN+ABG426rgYYbeGcIlWLZCw6Bx/1HtN5ef6nVEoiGNChYKIRB4QFOi
01smFxps1w8ZIQnD6wIDAQAB
-----END PUBLIC KEY-----';
        $rsa->loadKey($key);
        $rsa->setPublicKey();
        $newkey = $rsa->getPublicKey();
        $this->assertSame(preg_replace('#\\s#', '', $key), preg_replace('#\\s#', '', $newkey));
    }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:17,代码来源:LoadKeyTest.php

示例5: strlen

 static function crypt_rsa_key($mod, $exp, $hash = 'SHA256')
 {
     $rsa = new Crypt_RSA();
     $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
     $rsa->setHash(strtolower($hash));
     $rsa->modulus = new Math_BigInteger($mod, 256);
     $rsa->k = strlen($rsa->modulus->toBytes());
     $rsa->exponent = new Math_BigInteger($exp, 256);
     $rsa->setPublicKey();
     return $rsa;
 }
开发者ID:madcoda,项目名称:openpgp-php,代码行数:11,代码来源:openpgp_crypt_rsa.php

示例6: login

 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]));
                 }
             }
         }
     }
 }
开发者ID:hguenot,项目名称:yii2-gsftp,代码行数:27,代码来源:SftpDriver.php


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