Generate unique key
@return string
@throws SessionException
170231
private function getUniqueKey(): string
    {
        do {
            try {
                $isDuplicate = null;
                $key = random_bytes($this->getOpt(self::OPT_SESSION_KEY_LENGTH));

                // Ask for duplicate key from storage
                $this->emit('duplicate-check', [$key, &$isDuplicate]);

            } catch (\Exception $e) {
                throw new SessionException($e->getMessage(), SessionException::ERR_RANDOM_BYTES);
            }
        } while (isset($this->SESSION[$key]) || $isDuplicate === true);

        return $key;
    }
5050
private function genUID() {
        // HTTP_CLIENT_IP and HTTP_X_FORWARDE‌​D_FOR can be forged.
        // REMOTE_ADDR is the same for all clients connected to a proxy.
        $ip=@$_SERVER['HTTP_CLIENT_IP'].@$_SERVER['HTTP_X_FORWARDE‌​D_FOR'].@$_SERVER['REMOTE_ADDR'];
        // HTTP_USER_AGENT could be forge.
        $browser=@$_SERVER['HTTP_USER_AGENT'];
        return md5($ip.$browser);
    }
1071530
public function uniqueKeepIndex(): self
    {
        // INFO: \array_unique() can't handle e.g. "stdClass"-values in an array

        // init
        $array = $this->getArray();

        $this->array = \array_reduce(
            \array_keys($array),
            static function ($resultArray, $key) use ($array) {
                if (!\in_array($array[$key], $resultArray, true)) {
                    $resultArray[$key] = $array[$key];
                }

                return $resultArray;
            },
            []
        );
        $this->generator = null;

        if ($this->array === null) {
            $this->array = [];
        } else {
            $this->array = (array) $this->array;
        }

        return $this;
    }
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, '+/', '-_');
    }
1094989
public function generatePK()
    {
        $format = $this->pkFormat;
        $pk     = $this->_properties['primary_key'];
        if (isset($pk[1]))
            throw new Exception(sprintf(self::E_Composit, get_called_class(), __FUNCTION__), 1);

        $pk     = array_shift($pk);
        if (!$pk)
            throw new Exception(sprintf(self::E_PrimaryKey, get_called_class()), 1);

        $last = (int) $this
            ->select(($format['serial']?
                'right('.$pk.', '.$format['serial'].')':
                $pk).' as last')
            ->order($pk.' desc')
            ->read(1)
            ->last;

        // compile prefix format
        if (preg_match('/\{(?<date>.+)\}/', $format['prefix'], $match))
            $newPK = preg_replace('/\{.+\}/', date($match['date']), $format['prefix']);
        else
            $newPK = $format['prefix'];

        $newPK .= trim(str_pad($last+1, $format['serial'], $format['prefix']?'0':' ', STR_PAD_LEFT));

        return $newPK;
    }
1003203
public function generate(): string
    {
        $uniqueId = uniqid((string) rand(), true);

        return (string) md5($uniqueId);
    }
466114
protected function generate_key( $length = 64 ) {
		$unique  = md5( microtime() . rand() );
		$prepend = $this->identifier . '_batch_';

		return substr( $prepend . $unique, 0, $length );
	}
1207618
public function generateRequestKey()
    {
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $charactersLength = strlen($characters);
        $requestKey = '';
        for ($i = 0; $i < 40; $i++) {
            $requestKey .= $characters[rand(0, $charactersLength - 1)];
        }
        return $requestKey;
    }
674398
public function getKey()
    {
        $key = '';

        if ($this->clientCredentials instanceof ClientCredentials) {
            $key .= rawurlencode($this->clientCredentials->getSecret());
        }

        // Keep the ampersand even if both keys are empty.
        $key .= '&';

        if ($this->serverIssuedCredentials instanceof ServerIssuedCredentials) {
            $key .= rawurlencode($this->serverIssuedCredentials->getSecret());
        }

        return $key;
    }
1088947
public function key()
    {
        if (!self::$session) {
            Exception::i()->setMessage(self::ERROR_NOT_STARTED)->trigger();
        }

        return key($_SESSION);
    }
513891
protected function getUnavailableKeys()
	{
		preg_match_all('(' . preg_quote($this->keyPrefix) . '.)', $this->xsl, $matches);

		return array_unique($matches[0]);
	}
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;
    }
383927
public static function keyCreate(){
		return base64_encode(mcrypt_create_iv(
			 mcrypt_get_key_size(self::$crypt_cipher,self::$crypt_mode)
			,self::$crypt_rand
		));
	}
265912
public function generate(): string
    {
        try {
            return DefuseKey::createNewRandomKey()->saveToAsciiSafeString();
        } catch(EnvironmentIsBrokenException $e) {
            throw new CryptoException($e->getMessage(), $e->getCode(), $e);
        }
    }
812588
public function key()
    {
        if (is_null($this->current)) {
            return $this->getUniqueKey();
        }
        if ($this->current instanceof RecursiveLeafInterface) {
            return $this->current->key();
        }
    }
724744
protected function key()
    {
        $key = rawurlencode($this->clientCredentials->getSecret()).'&';

        if ($this->credentials !== null) {
            $key .= rawurlencode($this->credentials->getSecret());
        }

        return $key;
    }
523774
public function generate_single_key_prefix() {
        if ($this->keyprefixsingle === null) {
            $this->keyprefixsingle = $this->mode.'/'.$this->component.'/'.$this->area;
            $this->keyprefixsingle .= '/'.$this->get_cache_identifier();
            $identifiers = $this->get_identifiers();
            if ($identifiers) {
                foreach ($identifiers as $key => $value) {
                    $this->keyprefixsingle .= '/'.$key.'='.$value;
                }
            }
            $this->keyprefixsingle = md5($this->keyprefixsingle);
        }
        return $this->keyprefixsingle;
    }