Generate a private key

@return string
510262
public function generate() {
        $strong = false;
        $i = 0;

        while (!$strong && $this->maxTries > $i++) {
            $data = openssl_random_pseudo_bytes(32, $strong);
        }

        if (!$strong) {
            throw new RuntimeException('Could not generate private key');
        }

        // base64_encode to get a decent ascii compatible format, and trim ending ='s.
        $key = rtrim(base64_encode($data), '=');

        // We change +/ into -_ to avoid any human confusion with paths
        return strtr($key, '+/', '-_');
    }
678785
public function generateKey(array $options = array())
	{
		// Create the new encryption key[/pair] object.
		$key = new Key('simple');

		// Just a random key of a given length.
		$key->private = $this->_getRandomKey();
		$key->public  = $key->private;

		return $key;
	}
761197
protected function generateKey()
    {
        return Json::encode([
            'model' => \get_class($this->owner),
            'id'    => $this->owner->getPrimaryKey(),
            'key'   => $this->_key,
        ]);
    }
1004013
public function setPrivateKey($private_key)
    {
        // If the private key is a file name then convert it to
        // the contents of the file (which should be an RSA private
        // key in PEM format)
        if (file_exists($private_key)) {
            $this->private_key_text = file_get_contents($private_key);
        } elseif (! empty($private_key)) {
            $this->private_key_text = $private_key;
        }

        return $this;
    }
682405
private function generatePKIKeys()
    {
        // OPENSSL config
        $config = array(
            'digest_alg' => $this->settings['private_key']['digest_method'],
            'private_key_bits' => $this->settings['private_key']['bits'],
            'private_key_type' => $this->settings['private_key']['type'],
        );

        $privateKey = null;
        $resource = openssl_pkey_new($config);

        openssl_pkey_export($resource, $privateKey);

        if(!$privateKey) {
            throw new EncryptionException('Private key could not be generated');
        }

        $publicKeyDetails = openssl_pkey_get_details($resource);
        $publicKey = $publicKeyDetails['key'];

        return array($publicKey, $privateKey);
    }
782109
public function loadPrivateKey(PrivateKeyConfiguration $key) : PrivateKey
    {
        if ($key->isFile()) {
            $privateKey = File::getFileContents($key->getFilePath());
        } else {
            $privateKey = $key->getContents();
        }

        return PrivateKey::create($privateKey, $key->getPassPhrase());
    }
591487
public function generate()
    {
        // Make a new key pair
        /** @var resource $private_key */
        $private_key = openssl_pkey_new([
            'private_key_bits'      => 2048,
            'private_key_type'      => OPENSSL_KEYTYPE_RSA,
            'encrypt_key'           => false,
        ]);

        // Export the key pair to a string
        $this->private_key_text = '';
        openssl_pkey_export($private_key, $this->private_key_text);

        // Get the public key
        $public_key_data       = openssl_pkey_get_details($private_key);
        $this->public_key_text = $public_key_data['key'];

        return $this;
    }
1122029
public function getKeysUrl() {
        return Http\KeysUrl::factory(
            $this->getBaseUrl() . '/keys.json',
            $this->getConfig('privateKey'),
            $this->getPublicKey()
        );
    }
1338065
public function generateCacheKey(): string
    {
        $name = $this->getConnection()->getName();

        return \md5($name.$this->toSql().\serialize($this->getBindings()));
    }
788052
private function generatePrivateECKey(): JWK
    {
        return JWKFactory::createFromKeyFile($this->privateKeyPath, $this->privateKeySecret, [
            'kid' => $this->keyId,
            'alg' => 'ES512',
            'use' => 'sig'
        ]);
    }
1157336
public function generate()
    {
        if (is_null($this->publicKey)) {
            throw new \Exception('Public Key has not been set');
        }

        $compressedValue = $this->publicKey;

        if (empty($compressedValue)) {
            throw new \Exception('The Public Key needs to be generated.');
        }

        $step1 = Util::sha256(Util::binConv($compressedValue), true);

        $step2 = Util::ripe160($step1);

        $step3 = sprintf(
            '%s%s%s',
            self::SIN_VERSION,
            self::SIN_TYPE,
            $step2
        );

        $step4 = Util::twoSha256(Util::binConv($step3), true);

        $step5 = substr(bin2hex($step4), 0, 8);

        $step6 = $step3.$step5;

        $this->value = Base58::encode($step6);

        return $this;
    }
320322
public function generate()
    {
        if ($this->_getOpenSSLFunctionalityChecker()->isOpenSslRandomBytesGeneratorAvailable()) {
            $sSalt = bin2hex(openssl_random_pseudo_bytes(16));
        } else {
            $sSalt = $this->_customSaltGenerator();
        }

        return $sSalt;
    }
384087
private function generateKeys()
    {
        $content = [];
        for ($i = 0; $i < count($this->keys); $i++) {
            $holder = [];
            $value = !$this->option($this->keys[$i]) || $this->option($this->keys[$i]) === 'generate' ? str_random(64) : $this->option($this->keys[$i]);
            $holder['regex'] = str_replace_first($this->findRegExPlaceholder, $this->keys[$i], $this->findRegEx);
            $holder['value'] = $this->keys[$i] . '="' . $value . '"';
            array_push($content, $holder);
        }

        return $content;
    }
1284213
public function decryptByPrivateKey_data($data, $privatekey = '')
	{
		$RSACrypt = new RSACrypt();

		if ($privatekey != "") {  // if null use default
			$RSACrypt->privkey = $privatekey;
		}
		$decrypt_res = "";
		$datas = explode('@', $data);
		foreach ($datas as $value) {
			$decrypt_res = $decrypt_res . $RSACrypt->decryptByPrivateKey($value);
		}
		return $decrypt_res;
	}
219103
private function _generateSignatureKey()
    {
        $date_h = hash_hmac('sha256', $this->_date, 'AWS4' . $this->_aws_secret, true);
        $region_h = hash_hmac('sha256', $this->_region, $date_h, true);
        $service_h = hash_hmac('sha256', self::SERVICE, $region_h, true);
        $signing_h = hash_hmac('sha256', 'aws4_request', $service_h, true);

        return $signing_h;
    }
678971
public function generateAuthKey()
    {
        try {
            $this->auth_key = Yii::$app->security->generateRandomString(32);
        } catch (Exception $e) {
            throw $e;
        }
    }
854969
private function createKeys()
    {
        //Create Can Keys
        shuffle(Devbr\Can::$base);
        shuffle(Devbr\Can::$extra_base);
        file_put_contents($this->configKeyPath.'can.key', implode(Devbr\Can::$base)."\n".implode(Devbr\Can::$extra_base));

        $SSLcnf = [];
        $dn = [];

        //get configurations
        include $this->configKeyPath.'openssl.config.php';

        // Generate a new private (and public) key pair
        $privkey = openssl_pkey_new($SSLcnf);

        // Generate a certificate signing request
        $csr = openssl_csr_new($dn, $privkey, $SSLcnf);

        // You will usually want to create a self-signed certificate at this
        // point until your CA fulfills your request.
        // This creates a self-signed cert that is valid for 365 days
        $sscert = openssl_csr_sign($csr, null, $privkey, 365, $SSLcnf);

        //CERTIFICADO
        openssl_csr_export_to_file($csr, $this->configKeyPath.'certificate.crt', false);

        //CERTIFICADO AUTO-ASSINADO
        openssl_x509_export_to_file($sscert, $this->configKeyPath.'self_signed_certificate.cer', false);

        //CHAVE PRIVADA (private.pem)
        openssl_pkey_export_to_file($privkey, $this->configKeyPath.'private.key', null, $SSLcnf);

        //CHAVE PÚBLICA (public.key)
        file_put_contents($this->configKeyPath.'public.key', openssl_pkey_get_details($privkey)['key']);
    }