生成IPC key
@access private
@param string $project 项目标识名
@return integer
168014
private function _ftok($project) {
        if (function_exists('ftok'))   return ftok(__FILE__, $project);
        if(strtoupper(PHP_OS) == 'WINNT'){
            $s = stat(__FILE__);
            return sprintf("%u", (($s['ino'] & 0xffff) | (($s['dev'] & 0xff) << 16) |
            (($project & 0xff) << 24)));
        }else {
            $filename = __FILE__ . (string) $project;
            for($key = array(); sizeof($key) < strlen($filename); $key[] = ord(substr($filename, sizeof($key), 1)));
            return dechex(array_sum($key));
        }
    }
709293
protected function generatePrivateKey($path, $passphrase)
    {
        if ($passphrase) {
            $processArgs = sprintf('genrsa -out %s/private.pem -aes256 -passout pass:%s 4096', $path, $passphrase);
        } else {
            $processArgs = sprintf('genrsa -out %s/private.pem 4096', $path);
        }

        $this->generateKey($processArgs);
    }
333623
public static function generateSecretKey()
    {
        // make parameters file if not exists
        touch(self::getRootDir().'/config/parameters.yml');

        /* @var $manipulator Parameters */
        $manipulator = self::getContainer()->getManipulator('parameters');
        if (!$manipulator->get('secret')) {
            $manipulator->set('secret', SecretKey::generate());
        }
    }
1037229
@Override
  public String key() {
    return new StringBuilder().append(projectKey).append(":").append(projectRelativePath).toString();
  }
376502
static public function generate()
    {
        if (! extension_loaded('openssl')) {
            throw new \RuntimeException("Can only generate a remote desktop certificate when OpenSSL PHP extension is installed.");
        }
        
        // Generate a new private (and public) key pair
        $config = array(
            'config' => __DIR__ . '/../Resources/config/openssl.cnf'
        );
        $privkey = openssl_pkey_new($config);
        
        // Generate a certificate signing request
        $dn = array(
            "commonName" => "AzureDistributionBundle for Symfony Tools"
        );
        $csr = openssl_csr_new($dn, $privkey, $config);
        $sscert = openssl_csr_sign($csr, null, $privkey, 365, $config);
        
        return new self($privkey, $sscert);
    }
917667
public static function cryptoKeyName($project, $location, $keyRing, $cryptoKey)
    {
        return self::getCryptoKeyNameTemplate()->render([
            'project' => $project,
            'location' => $location,
            'key_ring' => $keyRing,
            'crypto_key' => $cryptoKey,
        ]);
    }
1024600
public function getPrivateKey($clean = false)
    {
        if ($clean) {
            return trim(str_replace(
                ['-----BEGIN PRIVATE KEY-----', '-----END PRIVATE KEY-----'],
                '',
                $this->certs['pkey']
            ));
        } else {
            return $this->certs['pkey'];
        }
    }
639652
public function updateProject(Project $project, $title, $type, $reference, $options = array())
    {
        // Set basic properties:
        $project->setTitle($title);
        $project->setType($type);
        $project->setReference($reference);
        $project->setAllowPublicStatus(0);

        // Handle extra project options:
        if (array_key_exists('ssh_private_key', $options)) {
            $project->setSshPrivateKey($options['ssh_private_key']);
        }

        if (array_key_exists('ssh_public_key', $options)) {
            $project->setSshPublicKey($options['ssh_public_key']);
        }

        if (array_key_exists('build_config', $options)) {
            $project->setBuildConfig($options['build_config']);
        }

        if (array_key_exists('allow_public_status', $options)) {
            $project->setAllowPublicStatus((int)$options['allow_public_status']);
        }

        if (array_key_exists('archived', $options)) {
            $project->setArchived((bool)$options['archived']);
        }

        if (array_key_exists('branch', $options)) {
            $project->setBranch($options['branch']);
        }

        if (array_key_exists('group', $options)) {
            $project->setGroup($options['group']);
        }

        // Allow certain project types to set access information:
        $this->processAccessInformation($project);

        // Save and return the project:
        return $this->projectStore->save($project);
    }
413325
public function getProjectsAndCacheResult()
    {
        $projects = $this->getProjects();

        app('tddd.cache')->put(Constants::CACHE_PROJECTS_KEY, sha1($projects->toJson()));

        return $projects;
    }
1019590
public function create_key() {
        $res = openssl_pkey_new($this->config);
        if($res == false) return false;
        openssl_pkey_export($res, $privKey, null, $this->config);
        $public_key = openssl_pkey_get_details($res);

        $this->privKey=$privKey;
        $this->pubKey=$public_key["key"];
        openssl_free_key($res);
        return array('public_key'=>$public_key["key"],'private_key'=>$privKey);
    }
377230
public function generateSessionKey()
    {
        if (!isset($this->cryptParams['keysize'])) {
            throw new Exception('Unknown key size for type "' . $this->type . '".');
        }
        $keysize = $this->cryptParams['keysize'];

        $key = openssl_random_pseudo_bytes($keysize);

        if ($this->type === self::TRIPLEDES_CBC) {
            /* Make sure that the generated key has the proper parity bits set.
             * Mcrypt doesn't care about the parity bits, but others may care.
            */
            for ($i = 0; $i < strlen($key); $i++) {
                $byte = ord($key[$i]) & 0xfe;
                $parity = 1;
                for ($j = 1; $j < 8; $j++) {
                    $parity ^= ($byte >> $j) & 1;
                }
                $byte |= $parity;
                $key[$i] = chr($byte);
            }
        }

        $this->key = $key;
        return $key;
    }
528900
public static PrivateKey generatePrivateKey(String algorithm, KeySpec keySpec) {
		return KeyUtil.generatePrivateKey(algorithm, keySpec);
	}
287784
public function setKey($key = null)
    {
        if (empty($key)) {

            $key = $this->get('private_key');

            if (empty($key)) {
                $key = gplcart_string_random();
                $this->set('private_key', $key);
            }

        } else {
            $this->set('private_key', $key);
        }

        return $this->key = $key;
    }
1161098
public function generateKeyPair($keyOption = null)
    {
        if (null === $keyOption) {
            $keyOption = new RsaKeyOption();
        }
        if (\is_int($keyOption)) {
            @trigger_error('Passing a keySize to "generateKeyPair" is deprecated since version 1.1 and will be removed in 2.0. Pass an instance of KeyOption instead', E_USER_DEPRECATED);
            $keyOption = new RsaKeyOption($keyOption);
        }
        Assert::isInstanceOf($keyOption, KeyOption::class);

        try {
            $privateKey = $this->generator->generatePrivateKey($keyOption);
        } catch (KeyGenerationException $e) {
            throw new KeyPairGenerationException('Fail to generate a KeyPair with the given options', 0, $e);
        }

        return new KeyPair(
            $privateKey->getPublicKey(),
            $privateKey
        );
    }
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);
    }
1107970
public function generate(PrivateKey $privateKey = null)
    {
        if ($privateKey instanceof PrivateKey) {
            $this->setPrivateKey($privateKey);
        }

        if (!empty($this->hex)) {
            return $this;
        }

        if (is_null($this->privateKey)) {
            throw new \Exception('Please `setPrivateKey` before you generate a public key');
        }

        if (!$this->privateKey->isGenerated()) {
            $this->privateKey->generate();
        }

        if (!$this->privateKey->isValid()) {
            throw new \Exception('Private Key is invalid and cannot be used to generate a public key');
        }

        $point = new Point(
            '0x'.substr(Secp256k1::G, 2, 64),
            '0x'.substr(Secp256k1::G, 66, 64)
        );

        $R = Util::doubleAndAdd(
            '0x'.$this->privateKey->getHex(),
            $point
        );

        $RxHex = Util::encodeHex($R->getX());
        $RyHex = Util::encodeHex($R->getY());

        $RxHex = str_pad($RxHex, 64, '0', STR_PAD_LEFT);
        $RyHex = str_pad($RyHex, 64, '0', STR_PAD_LEFT);

        $this->x   = $RxHex;
        $this->y   = $RyHex;
        $this->hex = sprintf('%s%s', $RxHex, $RyHex);
        $this->dec = Util::decodeHex($this->hex);

        return $this;
    }
157916
public static function createIpKey($ip, $returnFirstKey = false)
    {
        $mask = null;
        if (preg_match('/\//', $ip)) {
            list($ip, $mask) = explode('/', $ip, 2);
        }

        $parts = explode('.', $ip);
        if (!isset($parts[1])) {
            throw new IspecException('invalid ip IpHelper::createIpKey');
        }

        //for lower masks then 16
        if ($returnFirstKey || (null !== $mask && (int) $mask < 16)) {
            return $parts[0];
        }

        return $parts[0].'.'.$parts[1];
    }