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


PHP Crypt_RSA::setPublicKey方法代码示例

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


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

示例1: 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);
     }
 }
开发者ID:AlexTsumarov,项目名称:7pass-php-sdk,代码行数:29,代码来源:Configuration.php

示例2: 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));
    }
}
开发者ID:abcdlzy,项目名称:webshell-manager,代码行数:27,代码来源:CASignCert.php

示例3: Rsa

 public function Rsa()
 {
     $modulus = 'ACD53F4BE9665DF48A2A1E39F4E7CDFAA0833AD986DD09831E519974D4E0228F43D9E58AE9ECEE865093D12E3EA576337C431F95C1C979784B8BDC93F244E072631339E8208CC5DF1377CB10E5018842DA9889856190F339CE8344FA906B67738BE292206EFAB71D33A5FC7EB1C3DBEC2F9A1A59B286C2B30C5E2FA0980D65A9';
     $exponent = '010001';
     $rsa = new Crypt_RSA();
     $modulus = $this->convertion($modulus);
     $exponent = $this->convertion($exponent);
     $rsa->loadKey(array('n' => $modulus, 'e' => $exponent));
     $rsa->setPublicKey();
     return $rsa->getPublicKey();
 }
开发者ID:boscDev,项目名称:tevi,代码行数:11,代码来源:Rsa.class.php

示例4: generateKeyPair

 public function generateKeyPair($keyPath, $keySize = 1024)
 {
     $privKey = new \Crypt_RSA();
     extract($privKey->createKey($keySize));
     $privKey->loadKey($privatekey);
     $pubKey = new \Crypt_RSA();
     $pubKey->loadKey($publickey);
     $pubKey->setPublicKey();
     $subject = new \File_X509();
     $subject->setDNProp('id-of-organization', 'phpseclib demo cert');
     $subject->setPublicKey($pubKey);
     $issuer = new \File_X509();
     $issuer->setPrivateKey($privKey);
     $issuer->setDN($subject->getDN());
     $x509 = new \File_X509();
     $result = $x509->sign($issuer, $subject);
     file_put_contents($keyPath . '/private.key', $privKey->getPrivateKey());
     file_put_contents($keyPath . '/public.crt', $x509->saveX509($result));
 }
开发者ID:tiagogoddard,项目名称:cryptoapi,代码行数:19,代码来源:PhpKeyGenerator.php

示例5: encrypt

 public function encrypt()
 {
     $binaryKey = bin2hex(base64_decode(GOOGLE_DEFAULT_PUBLIC_KEY));
     $half = substr($binaryKey, 8, 256);
     $modulus = new Math_BigInteger(hex2bin($half), 256);
     $half = substr($binaryKey, 272, 6);
     $exponent = new Math_BigInteger(hex2bin($half), 256);
     $sha1 = sha1(base64_decode($googleDefaultPublicKey), true);
     $signature = "00" . bin2hex(substr($sha1, 0, 4));
     $rsa = new Crypt_RSA();
     $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_RAW);
     $rsa->loadKey(array("n" => $modulus, "e" => $exponent));
     $rsa->setPublicKey();
     $plain = "{$email}{$password}";
     $rsa->setEncryptionMode("CRYPT_RSA_ENCRYPTION_OAEP");
     $encrypted = bin2hex($rsa->encrypt($plain));
     $output = hex2bin($signature . $encrypted);
     $b64EncryptedPasswd = str_replace(array("+", "/"), array("-", "_"), mb_convert_encoding(base64_encode($output), "US-ASCII"));
     return $b64EncryptedPasswd;
 }
开发者ID:mgp25,项目名称:Google-Crypto,代码行数:20,代码来源:encrypt.php

示例6: login

 public function login($authcode = '', $twofactorcode = '')
 {
     $dologin = $this->getRSAkey();
     if ($dologin->publickey_mod && $dologin->publickey_exp && $dologin->timestamp) {
         $password = $this->config['password'];
         $rsa = new Crypt_RSA();
         $key = array('modulus' => new Math_BigInteger($dologin->publickey_mod, 16), 'publicExponent' => new Math_BigInteger($dologin->publickey_exp, 16));
         $rsa->loadKey($key, CRYPT_RSA_PUBLIC_FORMAT_RAW);
         $rsa->setPublicKey($key);
         $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
         $enc_password = base64_encode($rsa->encrypt($password));
         $login = $this->request('POST', 'https://steamcommunity.com/login/dologin/', array('password' => $enc_password, 'username' => $this->config['username'], 'twofactorcode' => $twofactorcode, 'emailauth' => $authcode, 'loginfriendlyname' => '', 'capatcha_text' => '', 'emailsteamid' => isset($this->accountdata['steamid']) ? $this->accountdata['steamid'] : '', 'rsatimestamp' => $dologin->timestamp, 'remember_login' => 'true', 'donotcache' => time()));
         $login = json_decode($login);
         if ($login->success == false) {
             if (isset($login->emailsteamid) && $login->emailauth_needed == true) {
                 if ($authcode == '') {
                     file_put_contents($this->config['datapath'] . '/logindata.json', json_encode(array('steamid' => $login->emailsteamid)));
                     $this->error('Please enter AUTHCODE available in your e-mail inbox (domain: ' . $login->emaildomain . ').');
                 } else {
                     $this->error('You enter bad authcode!');
                 }
             } else {
                 if ($login->requires_twofactor == true) {
                     if ($twofactorcode == '') {
                         $this->error('Please enter twofactorcode (mobile auth).');
                     } else {
                         $this->error('You enter bad twofactorcode!');
                     }
                 }
             }
         } else {
             preg_match_all('#g_sessionID\\s\\=\\s\\"(.*?)\\"\\;#si', $this->view('http://steamcommunity.com/id'), $matches);
             return array('steamid' => $login->transfer_parameters->steamid, 'sessionId' => $matches[1][0], 'cookies' => $this->cookiejarToString(file_get_contents('cookiejar.txt')));
         }
         return $login;
     } else {
         $this->error('Bad RSA!');
     }
     return $dologin;
 }
开发者ID:emdy,项目名称:php-steamlogin,代码行数:40,代码来源:main.php

示例7: loadCert

 /**
  * @param string $certPem
  * @param array $keyPairPems
  *   Pair of PEM-encoded keys.
  * @param string $caCertPem
  * @return \File_X509
  */
 public static function loadCert($certPem, $keyPairPems = NULL, $caCertPem = NULL)
 {
     $certObj = new \File_X509();
     if (isset($caCertPem)) {
         $certObj->loadCA($caCertPem);
     }
     if ($certPem) {
         $certObj->loadX509($certPem);
     }
     if (isset($keyPairPems['privatekey'])) {
         $privKey = new \Crypt_RSA();
         $privKey->loadKey($keyPairPems['privatekey']);
         $certObj->setPrivateKey($privKey);
     }
     if (isset($keyPairPems['publickey'])) {
         $pubKey = new \Crypt_RSA();
         $pubKey->loadKey($keyPairPems['publickey']);
         $pubKey->setPublicKey();
         $certObj->setPublicKey($pubKey);
     }
     return $certObj;
 }
开发者ID:riyadennis,项目名称:my_civicrm,代码行数:29,代码来源:X509Util.php

示例8: jwkToPem

function jwkToPem($jwk)
{
    $modulus = new Math_BigInteger(base64url_decode($jwk['n']), 256);
    $exponent = new Math_BigInteger(base64_decode($jwk['e']), 256);
    $rsa = new Crypt_RSA();
    $rsa->loadKey(array('n' => $modulus, 'e' => $exponent));
    $rsa->setPublicKey();
    return str_replace("\r", "", $rsa->getPublicKey());
    // This shit is written for DOS
}
开发者ID:smutt,项目名称:HOBA-server,代码行数:10,代码来源:crypto.php

示例9: testSignedPKCS1

    /**
     * @group github468
     */
    public function testSignedPKCS1()
    {
        $rsa = new Crypt_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:anthrotech,项目名称:laravel_sample,代码行数:17,代码来源:LoadKeyTest.php

示例10: createCrlDistCSR

 /**
  * Create a CSR for an authority that can issue CRLs.
  *
  * @param array $keyPair
  * @param string $dn
  * @return string
  *   PEM-encoded CSR.
  */
 public static function createCrlDistCSR($keyPair, $dn)
 {
     $privKey = new \Crypt_RSA();
     $privKey->loadKey($keyPair['privatekey']);
     $pubKey = new \Crypt_RSA();
     $pubKey->loadKey($keyPair['publickey']);
     $pubKey->setPublicKey();
     $csr = new \File_X509();
     $csr->setPrivateKey($privKey);
     $csr->setPublicKey($pubKey);
     $csr->setDN($dn);
     $csr->loadCSR($csr->saveCSR($csr->signCSR(Constants::CERT_SIGNATURE_ALGORITHM)));
     $csr->setExtension('id-ce-keyUsage', array('cRLSign'));
     $csrData = $csr->signCSR(Constants::CERT_SIGNATURE_ALGORITHM);
     return $csr->saveCSR($csrData);
 }
开发者ID:riyadennis,项目名称:my_civicrm,代码行数:24,代码来源:CA.php

示例11: getPublicKey

 /**
  * Gets the public key
  *
  * Returns a Crypt_RSA object or a false.
  *
  * @access public
  * @return Mixed
  */
 function getPublicKey()
 {
     if (!isset($this->currentCert) || !is_array($this->currentCert) || !isset($this->currentCert['tbsCertificate'])) {
         return false;
     }
     $key = $this->currentCert['tbsCertificate']['subjectPublicKeyInfo']['subjectPublicKey'];
     switch ($this->currentCert['tbsCertificate']['subjectPublicKeyInfo']['algorithm']['algorithm']) {
         case 'rsaEncryption':
             if (!class_exists('Crypt_RSA')) {
                 require_once 'Crypt/RSA.php';
             }
             $publicKey = new Crypt_RSA();
             $publicKey->loadKey($key);
             $publicKey->setPublicKey();
             break;
         default:
             return false;
     }
     return $publicKey;
 }
开发者ID:3tan,项目名称:rconfig,代码行数:28,代码来源:X509.php

示例12: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     // ask fields
     $options = ['countryName' => 'CN', 'stateOrProvinceName' => 'Shanghai', 'localityName' => 'Shanghai'];
     if (!$input->getOption('default')) {
         foreach ($options as $ask => $default) {
             $q = new Question($ask . '[' . $default . ']: ', $default);
             $options[$ask] = $helper->ask($input, $output, $q);
         }
     }
     $output->writeln('Generating CA private key...');
     $CAPrivKey = new \Crypt_RSA();
     $key = $CAPrivKey->createKey(2048);
     file_put_contents(Application::$CONFIG_DIRECTORY . '/cert-ca.key', $key['privatekey']);
     $output->writeln('Generating self-signed CA certificate...');
     $CAPrivKey->loadKey($key['privatekey']);
     $pubKey = new \Crypt_RSA();
     $pubKey->loadKey($key['publickey']);
     $pubKey->setPublicKey();
     $subject = new \File_X509();
     $subject->setDNProp('id-at-organizationName', 'OpenVJ Certificate Authority');
     foreach ($options as $prop => $val) {
         $subject->setDNProp('id-at-' . $prop, $val);
     }
     $subject->setPublicKey($pubKey);
     $issuer = new \File_X509();
     $issuer->setPrivateKey($CAPrivKey);
     $issuer->setDN($CASubject = $subject->getDN());
     $x509 = new \File_X509();
     $x509->setStartDate('-1 month');
     $x509->setEndDate('+3 year');
     $x509->setSerialNumber(chr(1));
     $x509->makeCA();
     $result = $x509->sign($issuer, $subject, 'sha256WithRSAEncryption');
     file_put_contents(Application::$CONFIG_DIRECTORY . '/cert-ca.crt', $x509->saveX509($result));
     $output->writeln('Generating background service SSL private key...');
     $privKey = new \Crypt_RSA();
     $key = $privKey->createKey(2048);
     file_put_contents(Application::$CONFIG_DIRECTORY . '/cert-bg-server.key', $key['privatekey']);
     $privKey->loadKey($key['privatekey']);
     $output->writeln('Generating background service SSL certificate...');
     $pubKey = new \Crypt_RSA();
     $pubKey->loadKey($key['publickey']);
     $pubKey->setPublicKey();
     $subject = new \File_X509();
     $subject->setPublicKey($pubKey);
     $subject->setDNProp('id-at-organizationName', 'OpenVJ Background Service Certificate');
     foreach ($options as $prop => $val) {
         $subject->setDNProp('id-at-' . $prop, $val);
     }
     $subject->setDomain('127.0.0.1');
     $issuer = new \File_X509();
     $issuer->setPrivateKey($CAPrivKey);
     $issuer->setDN($CASubject);
     $x509 = new \File_X509();
     $x509->setStartDate('-1 month');
     $x509->setEndDate('+3 year');
     $x509->setSerialNumber(chr(1));
     $result = $x509->sign($issuer, $subject, 'sha256WithRSAEncryption');
     file_put_contents(Application::$CONFIG_DIRECTORY . '/cert-bg-server.crt', $x509->saveX509($result));
     $output->writeln('Generating background service client private key...');
     $privKey = new \Crypt_RSA();
     $key = $privKey->createKey(2048);
     file_put_contents(Application::$CONFIG_DIRECTORY . '/cert-bg-client.key', $key['privatekey']);
     $privKey->loadKey($key['privatekey']);
     $output->writeln('Generating background service client certificate...');
     $pubKey = new \Crypt_RSA();
     $pubKey->loadKey($key['publickey']);
     $pubKey->setPublicKey();
     $subject = new \File_X509();
     $subject->setPublicKey($pubKey);
     $subject->setDNProp('id-at-organizationName', 'OpenVJ Background Service Client Certificate');
     foreach ($options as $prop => $val) {
         $subject->setDNProp('id-at-' . $prop, $val);
     }
     $issuer = new \File_X509();
     $issuer->setPrivateKey($CAPrivKey);
     $issuer->setDN($CASubject);
     $x509 = new \File_X509();
     $x509->setStartDate('-1 month');
     $x509->setEndDate('+3 year');
     $x509->setSerialNumber(chr(1));
     $x509->loadX509($x509->saveX509($x509->sign($issuer, $subject, 'sha256WithRSAEncryption')));
     $x509->setExtension('id-ce-keyUsage', array('digitalSignature', 'keyEncipherment', 'dataEncipherment'));
     $x509->setExtension('id-ce-extKeyUsage', array('id-kp-serverAuth', 'id-kp-clientAuth'));
     $result = $x509->sign($issuer, $x509, 'sha256WithRSAEncryption');
     file_put_contents(Application::$CONFIG_DIRECTORY . '/cert-bg-client.crt', $x509->saveX509($result));
 }
开发者ID:Tanklong,项目名称:openvj,代码行数:89,代码来源:CertificateGenerateCommand.php

示例13: 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:adecaneda,项目名称:openpgp-php,代码行数:11,代码来源:openpgp_crypt_rsa.php

示例14: array

$iPhoneDeviceCA = file_get_contents($iPhoneDeviceCAFile);
$CA_Certificate = new File_X509();
$CA_Certificate->setPrivateKey($CA_Key);
$CA_Certificate->loadX509($iPhoneDeviceCA);
// $CA_Certificate->setExtension( 'id-ce-authorityKeyIdentifier',
// $CA_Certificate->setKeyIdentifier ( base64_decode (
// 'sv4hI0SGlWp51YEmjnMQ2KdMjnQ=' ) ), false );
// Get And Store DeviceCertRequest Public Key.
$DeviceCertRequest = base64_decode($DeviceCertRequest);
$iPhoneDeviceVect = openssl_pkey_get_details(openssl_csr_get_public_key($DeviceCertRequest));
$iPhoneDevicePublicKey = $iPhoneDeviceVect['key'];
file_put_contents($DeviceCertRequest_PublicFile, $iPhoneDevicePublicKey);
// Load DeviceCertRequest Public Key.
$DeviceCertRequest_PublicKey = new Crypt_RSA();
$DeviceCertRequest_PublicKey->loadKey(file_get_contents($DeviceCertRequest_PublicFile));
$DeviceCertRequest_PublicKey->setPublicKey();
// Load CSR And get DN.
$DeviceCertRequest_CR = new File_X509();
$DeviceCertRequest_CR->loadCSR($DeviceCertRequest);
$doulCi_DN = $DeviceCertRequest_CR->getDNProp('id-at-commonName');
// Build the new Device Certificate.
$iPhoneDeviceCA = new File_X509();
// $iPhoneDeviceCA->loadCA ( $iPhoneDeviceCA );
$iPhoneDeviceCA->setPublicKey($DeviceCertRequest_PublicKey);
$iPhoneDeviceCA->setDN($DeviceCertRequest_CR->getDN(true));
$iPhoneDeviceCA->removeDNProp('id-at-commonName');
$iPhoneDeviceCA->setDN(array('rdnSequence' => array(array(array('type' => 'id-at-commonName', 'value' => array('ia5String' => $doulCi_DN))))));
$iPhoneDeviceCA->setStartDate('-1 day');
$iPhoneDeviceCA->setEndDate('+ 3 year');
$iPhoneDeviceCA->setSerialNumber('1184677871349854983709', 10);
// Sign Device Certificate.
开发者ID:K0smas,项目名称:Doulci-master,代码行数:31,代码来源:doulCi.PKI+-+copie.php

示例15:

$subject->setDNProp('id-at-organizationName', 'phpseclib demo CA');
$subject->setPublicKey($pubKey);
$issuer = new File_X509();
$issuer->setPrivateKey($CAPrivKey);
$issuer->setDN($CASubject = $subject->getDN());
$x509 = new File_X509();
$x509->makeCA();
$result = $x509->sign($issuer, $subject);
echo "the CA cert to be imported into the browser is as follows:\r\n\r\n";
echo $x509->saveX509($result);
echo "\r\n\r\n";
// create private key / x.509 cert for stunnel / website
$privKey = new Crypt_RSA();
extract($privKey->createKey());
$privKey->loadKey($privatekey);
$pubKey = new Crypt_RSA();
$pubKey->loadKey($publickey);
$pubKey->setPublicKey();
$subject = new File_X509();
$subject->setDNProp('id-at-organizationName', 'phpseclib demo cert');
$subject->setPublicKey($pubKey);
$issuer = new File_X509();
$issuer->setPrivateKey($CAPrivKey);
$issuer->setDN($CASubject);
$x509 = new File_X509();
$result = $x509->sign($issuer, $subject);
echo "the stunnel.pem contents are as follows:\r\n\r\n";
echo $privKey->getPrivateKey();
echo "\r\n";
echo $x509->saveX509($result);
echo "\r\n";
开发者ID:abcdlzy,项目名称:webshell-manager,代码行数:31,代码来源:1.php


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