Generate an an authentication key (symmetric-key cryptography)

@return AuthenticationKey
@throws CannotPerformOperation
@throws InvalidKey
@throws \TypeError
356006
public static function generateAuthenticationKey(): AuthenticationKey
    {
        // @codeCoverageIgnoreStart
        try {
            $secretKey = \random_bytes(\SODIUM_CRYPTO_AUTH_KEYBYTES);
        } catch (\Throwable $ex) {
            throw new CannotPerformOperation($ex->getMessage());
        }
        // @codeCoverageIgnoreEnd
        return new AuthenticationKey(
            new HiddenString($secretKey)
        );
    }
227904
protected static function getBase64EncryptionKey() {	    
	    $key = 'STANDARDKEYIFNOSERVER';
	    if(!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE')))
	        $key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE'));
	    
	    return $key;
	}
560595
public Key getKey() {
		if(key != null) {
			return key;
		} else if(keySpec != null && secretKeyFactory != null) {
			try {
				return key = secretKeyFactory.generateSecret(keySpec);
			} catch (InvalidKeySpecException e) {
				throw new RuntimeException(e);
			}
		}
		throw new IllegalStateException("Cannot produce key");
	}
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;
    }
1252741
public function generateActivationKey()
    {
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $charactersLength = strlen($characters);
        $activationKey = '';
        for ($i = 0; $i < 40; $i++) {
            $activationKey .= $characters[rand(0, $charactersLength - 1)];
        }
        return $activationKey;
    }
136135
public function generateSecurityCode()
    {
        $result = $this->getCertificatePrivateKey();
        $result .= $this->getOib();
        $result .= $this->getDateTime();
        $result .= $this->getInvoiceNumber()->getInvoiceNumber();
        $result .= $this->getInvoiceNumber()->getBusinessLocationCode();
        $result .= $this->getInvoiceNumber()->getPaymentDeviceCode();
        $result .= $this->getTotalValue();

        $this->setSecurityCode(md5($result));

        return $this;
    }
943200
public static byte[] generateKey() {
        CipherKeyGenerator cipherKeyGenerator = new CipherKeyGenerator();
        cipherKeyGenerator.init(new KeyGenerationParameters(new SecureRandom(), 128));
        return cipherKeyGenerator.generateKey();
    }
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;
    }
207167
KeyPair generateKeyPair(int keySize) throws Exception {
        KeyPairGenerator generator = KeyPairGenerator.getInstance(KEY_GENERATION_ALGORITHM, PROVIDER_NAME);
        generator.initialize(keySize, new SecureRandom());
        return generator.generateKeyPair();
    }
116762
public static byte[] generateHmacSha1Key() {
		try {
			KeyGenerator keyGenerator = KeyGenerator.getInstance(HMACSHA1_ALG);
			keyGenerator.init(DEFAULT_HMACSHA1_KEYSIZE);
			SecretKey secretKey = keyGenerator.generateKey();
			return secretKey.getEncoded();
		} catch (GeneralSecurityException e) {
			throw ExceptionUtil.unchecked(e);
		}
	}
84148
public function getKey()
    {
        $repository = $this->om->getRepository($this->modelName);
        $count = 0;

        do {
            ++$count;

            if ($count > static::MAX_API_KEY_GENERATION_ATTEMPTS) {
                throw new \RuntimeException(sprintf(
                    'Unable to generate a new api key, stopping after %d tries!',
                    static::MAX_API_KEY_GENERATION_ATTEMPTS
                ));
            }

            $key = $this->doGenerate();
        } while (null !== $repository->findOneBy(array($this->metadata->getPropertyName(ClassMetadata::API_KEY_PROPERTY) => $key)));

        return $key;
    }
296842
public function hashCode()
    {
        $validPk = null !== $this->getUserId() &&
            null !== $this->getRoleId();

        $validPrimaryKeyFKs = 2;
        $primaryKeyFKs = [];

        //relation user_role_fk_29554a to table user
        if ($this->aUser && $hash = spl_object_hash($this->aUser)) {
            $primaryKeyFKs[] = $hash;
        } else {
            $validPrimaryKeyFKs = false;
        }

        //relation user_role_fk_1ff99e to table role
        if ($this->aRole && $hash = spl_object_hash($this->aRole)) {
            $primaryKeyFKs[] = $hash;
        } else {
            $validPrimaryKeyFKs = false;
        }

        if ($validPk) {
            return crc32(json_encode($this->getPrimaryKey(), JSON_UNESCAPED_UNICODE));
        } elseif ($validPrimaryKeyFKs) {
            return crc32(json_encode($primaryKeyFKs, JSON_UNESCAPED_UNICODE));
        }

        return spl_object_hash($this);
    }
605613
private function _prepareSigningKey()
	{
		return $this->safeEncode($this->getOption('consumer_secret')) . '&' . $this->safeEncode(($this->token) ? $this->token['secret'] : '');
	}
215315
public function generateKey()
    {
        if (extension_loaded('openssl')) {
            $key = openssl_random_pseudo_bytes(16);
        } else {
            // SHA1 is 128 bit (= 16 bytes)
            $key = sha1(spl_object_hash($this) . mt_rand(0, PHP_INT_MAX) . uniqid('', true), true);
        }

        return base64_encode($key);
    }
1177734
protected function getEncryptionKey()
    {
        if ($this->encryptionKey === null) {
            $this->encryptionKey = $this->cache->get('encryptionKey');
        }
        if ($this->encryptionKey === false && file_exists(FLOW_PATH_DATA . 'Persistent/EncryptionKey')) {
            $this->encryptionKey = file_get_contents(FLOW_PATH_DATA . 'Persistent/EncryptionKey');
        }
        if ($this->encryptionKey === false) {
            $this->encryptionKey = bin2hex(Utility\Algorithms::generateRandomBytes(48));
            $this->cache->set('encryptionKey', $this->encryptionKey);
        }
        return $this->encryptionKey;
    }
729871
public function getEccKey() : PublicKeyInterface
    {
        $math = EccFactory::getAdapter();
        $generator = EccFactory::getNistCurves()->generator256();
        $pointSerializer = new UncompressedPointSerializer($math);
        $point = $pointSerializer->unserialize($generator->getCurve(), bin2hex($this->getRawKeyMaterial()));

        return $generator->getPublicKeyFrom($point->getX(), $point->getY(), $generator->getOrder());
    }
385049
public function authenticate()
    {
        if (!empty($this->hashedPassword)) {
            return $this->authenticateWithPassword($this->login, $this->getTokenAuthSecret());
        } elseif (is_null($this->login)) {
            return $this->authenticateWithToken($this->token_auth);
        } elseif (!empty($this->login)) {
            return $this->authenticateWithLoginAndToken($this->token_auth, $this->login);
        }

        return new AuthResult(AuthResult::FAILURE, $this->login, $this->token_auth);
    }