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


PHP RSA::setPublicKeyFormat方法代码示例

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


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

示例1: 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

示例2: handle

 public function handle($data)
 {
     $rsa = new RSA();
     $rsa->setPrivateKeyFormat(RSA::PRIVATE_FORMAT_XML);
     $rsa->setPublicKeyFormat(RSA::PRIVATE_FORMAT_XML);
     return ["assignment" => Token::generateNewToken(TOKEN_ASSIGNMENT)->toExternalForm(false)];
 }
开发者ID:JamesFitzpatrick-Coursework,项目名称:Web-API,代码行数:7,代码来源:TestEndpoint.php

示例3: createKey

 /**
  * Generate a keypair
  *
  * @return array ['privatekey' => $privateKey, 'publickey' => $publicKey]
  */
 public function createKey()
 {
     $rsa = new RSACrypt();
     $rsa->setPublicKeyFormat(RSACrypt::PUBLIC_FORMAT_OPENSSH);
     $rsa->setPassword($this->config->getSystemValue('secret', ''));
     return $rsa->createKey(self::CREATE_KEY_BITS);
 }
开发者ID:farukuzun,项目名称:core-1,代码行数:12,代码来源:rsa.php

示例4: 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

示例5: generateKeyPair

 public static function generateKeyPair($comment = 'dogpro')
 {
     $rsa = new RSA();
     $rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_OPENSSH);
     $rsa->setComment($comment);
     return $rsa->createKey();
 }
开发者ID:dzirg44,项目名称:dogpro,代码行数:7,代码来源:SSH.php

示例6: doGenerateKeys

 protected static function doGenerateKeys($keySize = 2048)
 {
     $rsa = new Crypt_RSA();
     $rsa->setPrivateKeyFormat(Crypt_RSA::PRIVATE_FORMAT_PKCS1);
     $rsa->setPublicKeyFormat(Crypt_RSA::PUBLIC_FORMAT_PKCS1);
     defined('CRYPT_RSA_EXPONENT') || define('CRYPT_RSA_EXPONENT', 65537);
     defined('CRYPT_RSA_SMALLEST_PRIME') || define('CRYPT_RSA_SMALLEST_PRIME', 64);
     return $rsa->createKey($keySize);
 }
开发者ID:highestgoodlikewater,项目名称:yii2-token-storage,代码行数:9,代码来源:BaseKeyPair.php

示例7: generateSshKeys

 private function generateSshKeys()
 {
     $rsa = new RSA();
     $rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_OPENSSH);
     $rsa->setPassword(\OC::$server->getConfig()->getSystemValue('secret', ''));
     $key = $rsa->createKey();
     // Replace the placeholder label with a more meaningful one
     $key['publicKey'] = str_replace('phpseclib-generated-key', gethostname(), $key['publickey']);
     return $key;
 }
开发者ID:rosarion,项目名称:core,代码行数:10,代码来源:ajaxcontroller.php

示例8: onRun

 public function onRun()
 {
     foreach ($this->loadPaths as $name => $path) {
         if (!class_exists($name, false) and !interface_exists($name, false)) {
             require $path;
         }
     }
     $this->loader->register(true);
     $rsa = new RSA();
     $this->logger->info("[BigBrother] Generating keypair");
     $rsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
     $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_PKCS1);
     $keys = $rsa->createKey(1024);
     $this->setResult($keys);
 }
开发者ID:MrGenga,项目名称:BigBrother,代码行数:15,代码来源:GeneratePrivateKey.php

示例9: generateKeys

 /**
  * Generates a new key pair. Then stores the private key and returns the public key.
  *
  * @param int $keylength Desired key length in bits
  * @return array The public key as an associative array containing its exponent "e"
  *               and modulus "n" in hexadecimal representation.
  */
 public static function generateKeys($keylength)
 {
     $rsa = new RSA();
     $rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_RAW);
     $keys = $rsa->createKey($keylength);
     static::deletePrivateKeyTable();
     // delete, if exists - future-proofing for layout changes
     static::createPrivateKeyTable();
     // create, if doesn't exist
     static::storePrivateKey($keys['privatekey']);
     $e = new BigInteger($keys['publickey']['e'], 10);
     $n = new BigInteger($keys['publickey']['n'], 10);
     $e = $e->toHex();
     $n = $n->toHex();
     $publickey = array('e' => $e, 'n' => $n);
     static::writePublicKeyJS($publickey);
     return $publickey;
 }
开发者ID:Joey3000,项目名称:piwik-LoginEncrypted,代码行数:25,代码来源:Crypto.php

示例10: createRSA

 protected function createRSA()
 {
     $rsa = new RSA();
     $rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_OPENSSH);
     $rsa->setComment($this->config['routerboard']['backupuser'] . "@backup");
     $key = $rsa->createKey(2048);
     if (!empty($key)) {
         // be safe
         $this->backupExistRSA();
         // create id_rsa.pub (public key)
         $this->fsys->dumpFile($this->config['system']['ssh-dir'] . DIRECTORY_SEPARATOR . 'id_rsa.pub', $key['publickey']);
         // create id_rsa (private key)
         $this->fsys->dumpFile($this->config['system']['ssh-dir'] . DIRECTORY_SEPARATOR . 'id_rsa', $key['privatekey']);
         // set permissions -rw-------
         $this->fsys->chmod($this->config['system']['ssh-dir'] . DIRECTORY_SEPARATOR . 'id_rsa', 0600);
         $this->fsys->chmod($this->config['system']['ssh-dir'] . DIRECTORY_SEPARATOR . 'id_rsa.pub', 0600);
         // backup existing RSA files for sure.
         $this->backupExistRSA('routerboard-backup');
         $this->logger->log("The SSH-RSA public key has been created. Never delete those files! (id_rsa,id_rsa.pub)", $this->logger->setNotice());
         return;
     }
     throw new Exception(get_class($this) . " can not create the ssh-rsa public key file!");
 }
开发者ID:heximcz,项目名称:routerboard-backup,代码行数:23,代码来源:SecureTools.php

示例11: generateKeys

 public function generateKeys($token)
 {
     $rsa = new RSA();
     $rsa->setPrivateKeyFormat(RSA::PRIVATE_FORMAT_PKCS8);
     $rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_PKCS8);
     $keys = $rsa->createKey(4096);
     $items = $this->entity_manager->getRepository('PasswordSafeBundle:SharedPassword')->findByReceiver($token->getUser());
     $rsaOld = new RSA();
     $rsaOld->loadKey($this->databaseService->getMeta($token)->get('privateKey'));
     $meta = $this->databaseService->getMeta($token);
     $meta->add('privateKey', $keys['privatekey']);
     $meta->add('publicKey', $keys['publickey']);
     $this->databaseService->saveMetaRow($token, $meta);
     $token->getUser()->setPublicKey($keys['publickey']);
     $this->entity_manager->persist($token->getUser());
     $this->entity_manager->flush();
     $rsa->loadKey($token->getUser()->getPublicKey());
     foreach ($items as $item) {
         $decrypted = $rsaOld->decrypt($item->getEncryptedData());
         $item->setEncryptedData($rsa->encrypt($decrypted));
         $this->entity_manager->persist($item);
     }
     $this->entity_manager->flush();
 }
开发者ID:flobbie,项目名称:PasswordSafe,代码行数:24,代码来源:RSAService.php

示例12: getPair

 public function getPair()
 {
     $installationUuid = $this->name;
     $publicKeyName = $this->getPublicKeyPath();
     $privateKeyName = $this->getPrivateKeyPath();
     if (Storage::exists($publicKeyName) === false || Storage::exists($privateKeyName) === false) {
         $rsa = new RSA();
         $rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_OPENSSH);
         $rsa->setComment('fodor@fodor.xyz');
         $keys = $rsa->createKey(2048);
         $privateKey = $keys['privatekey'];
         $publicKey = $keys['publickey'];
         Storage::disk('local')->put($privateKeyName, $privateKey);
         Storage::disk('local')->put($publicKeyName, $publicKey);
     }
     return ['public' => $publicKeyName, 'private' => $privateKeyName];
     /*$sshConnection = ssh2_connect('mycloud.smellynose.com', 22, array('hostkey'=>'ssh-rsa'));
       $sshSuccess = ssh2_auth_pubkey_file(
           $sshConnection,
           'ahindle',
           storage_path('app/' . $publicKeyName),
           storage_path('app/' . $privateKeyName)
       );*/
 }
开发者ID:fodorxyz,项目名称:fodor,代码行数:24,代码来源:Keys.php

示例13: recreateRSAKeys

 /**
  * Regenerate and return the private and public keys for a user
  *
  * @author salvipascual
  * @param String $email
  * @return Array(privatekey, publickey)
  * */
 public function recreateRSAKeys($email)
 {
     // create the public and private keys
     $rsa = new RSA();
     $rsa->setPublicKeyFormat(RSA::PUBLIC_FORMAT_OPENSSH);
     $keys = $rsa->createKey();
     $privatekey = $keys['privatekey'];
     $publickey = $keys['publickey'];
     // update the new keys or create a new pair
     $connection = new Connection();
     $connection->deepQuery("INSERT INTO `keys` (email, privatekey, publickey) VALUES('{$email}', '{$privatekey}', '{$publickey}') ON DUPLICATE KEY UPDATE privatekey='{$privatekey}', publickey='{$publickey}', last_usage=CURRENT_TIMESTAMP");
     // return the new keys
     return array("privatekey" => $privatekey, "publickey" => $publickey);
 }
开发者ID:Apretaste,项目名称:Core,代码行数:21,代码来源:Utils.php

示例14: testRawKey

 public function testRawKey()
 {
     $rsa = new RSA();
     $key = array('e' => new BigInteger('10001', 16), 'n' => new BigInteger('aa18aba43b50deef38598faf87d2ab634e4571c130a9bca7b878267414faab8b471bd8965f5c9fc3' . '818485eaf529c26246f3055064a8de19c8c338be5496cbaeb059dc0b358143b44a35449eb2641131' . '21a455bd7fde3fac919e94b56fb9bb4f651cdb23ead439d6cd523eb08191e75b35fd13a7419b3090' . 'f24787bd4f4e1967', 16));
     $this->assertTrue($rsa->load($key));
     $rsa->setPublicKeyFormat('raw');
     $this->assertEmpty("{$rsa}");
 }
开发者ID:pandidan,项目名称:phpseclib,代码行数:8,代码来源:LoadKeyTest.php


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