当前位置: 首页>>代码示例>>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;未经允许,请勿转载。