當前位置: 首頁>>代碼示例>>PHP>>正文


PHP RSA::createKey方法代碼示例

本文整理匯總了PHP中phpseclib\Crypt\RSA::createKey方法的典型用法代碼示例。如果您正苦於以下問題:PHP RSA::createKey方法的具體用法?PHP RSA::createKey怎麽用?PHP RSA::createKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在phpseclib\Crypt\RSA的用法示例。


在下文中一共展示了RSA::createKey方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __construct

 public function __construct($publicKey = '', $privateKey = '')
 {
     $this->rsa = new RSA();
     if (!$publicKey || !$privateKey) {
         $keys = $this->rsa->createKey();
         $this->publicKey = $keys['publickey'];
         $this->privateKey = $keys['privatekey'];
         return;
     }
     $this->publicKey = $publicKey;
     $this->privateKey = $privateKey;
 }
開發者ID:naoned,項目名稱:ednaoClient,代碼行數:12,代碼來源:EdnaoCryptography.php

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

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

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

示例5: testCreateKey

 public function testCreateKey()
 {
     extract(RSA::createKey(512));
     $this->assertInstanceOf('\\phpseclib\\Crypt\\RSA', $privatekey);
     $this->assertInstanceOf('\\phpseclib\\Crypt\\RSA', $publickey);
     $this->assertNotEmpty("{$privatekey}");
     $this->assertNotEmpty("{$publickey}");
     return array($publickey, $privatekey);
 }
開發者ID:maaking,項目名稱:phpseclib,代碼行數:9,代碼來源:CreateKeyTest.php

示例6: generateKeyPair

 /**
  * Generate a private/public RSA key pair
  *
  * @param int $size Key size
  * @param string $passphrase Optional - password-protected private key
  *
  * @return self
  * @throws InvalidKeyException
  */
 public static function generateKeyPair($size = 2048)
 {
     if ($size < 2048) {
         throw new InvalidKeyException('Key size must be at least 2048 bits.');
     }
     $rsa = new RSA();
     $keypair = $rsa->createKey($size);
     return new KeyPair(new PrivateKey($keypair['privatekey']), new PublicKey($keypair['publickey']));
 }
開發者ID:paragonie,項目名稱:easyrsa,代碼行數:18,代碼來源:KeyPair.php

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

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

示例9: createKeys

 /**
  * Create domain RSA keys
  *
  * @return KeyPair
  * @throws \Exception
  */
 public function createKeys()
 {
     $rsa = new RSA();
     $keys = $rsa->createKey(2048);
     if ($keys['partialkey'] === false) {
         $this->domainKeys = new KeyPair($keys['privatekey'], $keys['publickey']);
     } else {
         throw new \Exception('CPU was to slow, we\'ve not yet coded this part.');
     }
     return $this->domainKeys;
 }
開發者ID:Petertjuh360,項目名稱:da-letsencrypt,代碼行數:17,代碼來源:Domain.php

示例10: genRsa

 /**
  * Generate a 4096 bits RSA private key
  * @return array the PEM-encoded version of the unprotected private and public keys.
  */
 function genRsa()
 {
     $rsa = new RSA();
     $privKey = $rsa->createKey(4096);
     // TODO handle timeout?
     if (isset($privKey["partialkey"])) {
         unset($privKey["partialkey"]);
     }
     return $privKey;
     // hash with privatekey and publickey
 }
開發者ID:mduplouy,項目名稱:acmephpc,代碼行數:15,代碼來源:SslPhpseclib.php

示例11: generate

 public static function generate($bits = 2048, $password = '')
 {
     $bits = (int) $bits;
     $rsa = new RSA();
     if (!empty($password)) {
         $rsa->setPassword($password);
     }
     $keys = $rsa->createKey($bits);
     $publicKey = new SshPublicKey($keys['publickey']);
     $privateKey = new SshPrivateKey($keys['privatekey'], $password);
     return new SshKeyPair($publicKey, $privateKey);
 }
開發者ID:codeaken,項目名稱:sshkey,代碼行數:12,代碼來源:SshKeyPair.php

示例12: indexAction

 /**
  * @Route("/asd", name="homepage")
  */
 public function indexAction(Request $request)
 {
     $request = $this->get('request');
     $defaultData = array('name' => 'Type your file name here');
     $form = $this->createFormBuilder($defaultData)->add('name', 'text')->add('file', 'file', array('mapped' => false))->add('submit', 'submit')->getForm();
     if ($request->getMethod() == 'POST') {
         $form->handleRequest($this->get('request'));
         if ($form->isValid()) {
             // perform some action, such as saving the task to the database
             $data = $form->getData();
             if ($form['file']->getData()) {
                 $filename = $form['file']->getData()->getClientOriginalName();
                 $uploadDir = dirname($this->container->getParameter('kernel.root_dir')) . '/web/bundles/framework/upload';
                 $form['file']->getData()->move($uploadDir, $filename);
                 $link = '/web/bundles/framework/upload' . '/' . $filename;
             }
         }
         $inputFile = $request->files->get('cache.xml');
         return $this->render('default/index.html.twig', array('cipher' => "", 'plain' => "", 'rsacipher' => "", 'rsaplain' => "", 'rsapk' => "", 'form' => $form->createView(), 'link' => $link));
     } else {
         $des = new DES();
         echo gettype($des);
         $des->setKey('This is my secret key');
         $plaintext = 'asda sda sdas dasd asdasdada sd';
         $cipher = $des->encrypt($plaintext);
         $plain = $des->decrypt($cipher);
         $rsa = new RSA();
         $rsa->createKey(1024);
         $rsaplain = "encrypt using RSA";
         $key = $rsa->createKey(1024);
         $rsa->loadKey($key['publickey']);
         $rsacipher = $rsa->encrypt($rsaplain);
         $rsa->loadKey($key['privatekey']);
         $rsadec = $rsa->decrypt($rsacipher);
         // replace this example code with whatever you need
         return $this->render('default/index.html.twig', array('base_dir' => realpath($this->container->getParameter('kernel.root_dir') . '/..'), 'cipher' => $cipher, 'plain' => $plain, 'rsacipher' => $key['publickey'], 'rsaplain' => $key['privatekey'], 'rsapk' => $rsa->getPublicKey(), 'form' => $form->createView()));
     }
 }
開發者ID:ngockhiem27,項目名稱:AES-DES-RSA,代碼行數:41,代碼來源:DefaultController.php

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

示例14: createKeys

 /**
  * Create and save a key pair for user
  *
  * @return KeyPair
  * @throws \Exception
  */
 public function createKeys()
 {
     $rsa = new RSA();
     $keys = $rsa->createKey(2048);
     if ($keys['partialkey'] === false) {
         $this->keyPair = new KeyPair($keys['privatekey'], $keys['publickey']);
         $this->writeToStorage('public.key', $this->keyPair->getPublic());
         $this->writeToStorage('private.key', $this->keyPair->getPrivate());
         $this->config('status', 'keys generated');
     } else {
         throw new \Exception('CPU was to slow, we\'ve not yet coded this part.');
     }
     $this->acme = new AcmeService(new AcmeClient($this->acmeServer, $this->keyPair), $this->keyPair);
     return $this->keyPair;
 }
開發者ID:Petertjuh360,項目名稱:da-letsencrypt,代碼行數:21,代碼來源:Account.php

示例15: testSaveSPKAC

 public function testSaveSPKAC()
 {
     $privKey = new RSA();
     extract($privKey->createKey());
     $x509 = new X509();
     $x509->setPrivateKey($privatekey);
     $x509->setChallenge('...');
     $spkac = $x509->signSPKAC();
     $this->assertInternalType('array', $spkac);
     $this->assertInternalType('string', $x509->saveSPKAC($spkac));
     $x509 = new X509();
     $x509->setPrivateKey($privKey);
     $spkac = $x509->signSPKAC();
     $this->assertInternalType('array', $spkac);
     $this->assertInternalType('string', $x509->saveSPKAC($spkac));
 }
開發者ID:maaking,項目名稱:phpseclib,代碼行數:16,代碼來源:SPKACTest.php


注:本文中的phpseclib\Crypt\RSA::createKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。