src/Util/Crypto.php
private static function deriveKeys(string $key, string $salt, bool $password = false)
    {
        if ($password) {
            $preHash = \hash(self::HASH_TYPE, $key, true);
            $key = self::pbkdf2(
                self::HASH_TYPE,
                $preHash,
                $salt,
                self::PBKDF2_ITERATIONS,
                self::KEY_BYTE_SIZE,
                true
            );
        }

        $authKey = self::hkdf(
            self::HASH_TYPE,
            $key,
            self::KEY_BYTE_SIZE,
            self::AUTHENTICATION_INFO_STRING,
            $salt
        );

        $encryptKey = self::hkdf(
            self::HASH_TYPE,
            $key,
            self::KEY_BYTE_SIZE,
            self::ENCRYPTION_INFO_STRING,
            $salt
        );

        return [$authKey, $encryptKey];
    }
private static function deriveKeys(string $key, string $salt, bool $password = false)
    {
        if ($password) {
            $preHash = \hash(self::HASH_TYPE, $key, true);
            $key = self::pbkdf2(
                self::HASH_TYPE,
                $preHash,
                $salt,
                self::PBKDF2_ITERATIONS,
                self::KEY_BYTE_SIZE,
                true
            );
        }

        $authKey = self::hkdf(
            self::HASH_TYPE,
            $key,
            self::KEY_BYTE_SIZE,
            self::AUTHENTICATION_INFO_STRING,
            $salt
        );

        $encryptKey = self::hkdf(
            self::HASH_TYPE,
            $key,
            self::KEY_BYTE_SIZE,
            self::ENCRYPTION_INFO_STRING,
            $salt
        );

        return [$authKey, $encryptKey];
    }
private static function deriveKeys ( string $ key , string $ salt , bool $ password = false ) { if ( $ password ) { $ preHash = \ hash ( self :: HASH_TYPE , $ key , true ) ; $ key = self :: pbkdf2 ( self :: HASH_TYPE , $ preHash , $ salt , self :: PBKDF2_ITERATIONS , self :: KEY_BYTE_SIZE , true ) ; } $ authKey = self :: hkdf ( self :: HASH_TYPE , $ key , self :: KEY_BYTE_SIZE , self :: AUTHENTICATION_INFO_STRING , $ salt ) ; $ encryptKey = self :: hkdf ( self :: HASH_TYPE , $ key , self :: KEY_BYTE_SIZE , self :: ENCRYPTION_INFO_STRING , $ salt ) ; return [ $ authKey , $ encryptKey ] ; }
Derives authentication and encryption keys from the secret, using a slow
key derivation function if the secret is a password.

@param string $key
@param string $salt
@param bool   $password

@throws CryptoException

@return array
Derives authentication and encryption keys from the secret using a slow key derivation function if the secret is a password .