Check if key and value is valid and able to crypt or decrypt

@param string $key
@param string $value
@return bool
542362
protected function valid(string $key, string $value)
    {
        return in_array($key, $this->encryptable) && !is_null($value) && !empty($value);
    }
1307389
public function secureSet(string $key, $value = null)
    {
        try {
            if ($this->encrypter instanceof Encrypter) {
                $value = $this->encrypter->encrypt($value);
            }
        } catch (EncryptException $e) {
            //
        }

        return $this->set($key, $value);
    }
850675
public function set($key, $value) {
        $key = $this->secureKey($key);
        $_SESSION[$key] = $this->secureValue($value);
        
        return $key;
    }
438013
public function has(string $key, $value = null): bool
    {
        return is_null($value)
            ? isset($_SESSION[$key])
            : isset($_SESSION[$key]) && $_SESSION[$key] == $value;
    }
988251
public function contains($key, $value)
    {
        if (isset($this->values[$key])) {
            return $this->values[$key]->contains($value);
        }

        return false;
    }
360606
protected function isValidValue($value)
    {
        $valid = true;
        if (is_array($value)) {
            $numericKeys = 0;
            foreach ($value as $k => $v) {
                $numericKeys += is_integer($k);
                if (!$this->isValidValue($v)) {
                    $valid = false;
                    break;
                }
            }
            if (!($numericKeys == 0 || $numericKeys == count($value))) {
                $valid = false;
            }
        } else {
            if (null !== $value && !is_scalar($value)) {
                $valid = false;
            }
        }
        return $valid;
    }
835230
public function decrypt($value)
    {
        $decrypted = "";
        $envelope  = current($this->getEnvelopeKey());

        if (count($this->keys['private']) !== 1) {
            throw new Exception\RuntimeException('Please give a private key for decryption with Openssl');
        }

        if (!$this->package && empty($envelope)) {
            throw new Exception\RuntimeException('Please give an envelope key for decryption with Openssl');
        }

        foreach ($this->keys['private'] as $cert) {
            $keys = openssl_pkey_get_private($cert, $this->getPassphrase());
        }

        if ($this->package) {
            $details = openssl_pkey_get_details($keys);
            if ($details !== false) {
                $fingerprint = md5($details['key']);
            } else {
                $fingerprint = md5("ZendFramework");
            }

            $count = unpack('ncount', $value);
            $count = $count['count'];
            $length  = 2;
            for ($i = $count; $i > 0; --$i) {
                $header = unpack('H32print/nsize', substr($value, $length, 18));
                $length  += 18;
                if ($header['print'] == $fingerprint) {
                    $envelope = substr($value, $length, $header['size']);
                }

                $length += $header['size'];
            }

            // remainder of string is the value to decrypt
            $value = substr($value, $length);
        }

        $crypt  = openssl_open($value, $decrypted, $envelope, $keys);
        openssl_free_key($keys);

        if ($crypt === false) {
            throw new Exception\RuntimeException('Openssl was not able to decrypt you content with the given options');
        }

        // decompress after decryption
        if (!empty($this->compression)) {
            $decompress = new Decompress($this->compression);
            $decrypted  = $decompress($decrypted);
        }

        return $decrypted;
    }
665194
public function encrypt($value)
    {
        $iv = random_bytes(openssl_cipher_iv_length($this->cipher));

        $value = openssl_encrypt($value, $this->cipher, $this->key, 0, $iv);

        if ($value === false) {
            throw new EncryptException('Could not encrypt the data.');
        }

        $iv = base64_encode($iv);

        return base64_encode(json_encode(compact('iv', 'value')));
    }
550960
protected function _decode($value, $encrypt, $key)
    {
        if (!$encrypt) {
            return $this->_explode($value);
        }
        $this->_checkCipher($encrypt);
        $prefix = 'Q2FrZQ==.';
        $prefixLength = strlen($prefix);

        if (strncmp($value, $prefix, $prefixLength) !== 0) {
            return '';
        }

        $value = base64_decode(substr($value, $prefixLength), true);

        if ($value === false || $value === '') {
            return '';
        }

        if ($key === null) {
            $key = $this->_getCookieEncryptionKey();
        }
        if ($encrypt === 'rijndael') {
            $value = Security::rijndael($value, $key, 'decrypt');
        }
        if ($encrypt === 'aes') {
            $value = Security::decrypt($value, $key);
        }

        if ($value === false) {
            return '';
        }

        return $this->_explode($value);
    }
436826
private function encrypt($value)
    {
        $this->checkKey();

        $iv = mcrypt_create_iv(16, MCRYPT_DEV_URANDOM);
        $cipher = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->key, json_encode($value), 'ctr', $iv);
        $hmac = hash_hmac('sha256', $iv.$cipher, $this->authentication, true);

        return base64_encode($hmac.$iv.$cipher);
    }
942812
public static function hasKeyAndValue(string $key, $value): bool
    {
        static::startSessionIfNotHasStarted();

        return \array_key_exists($key, $_SESSION) && $_SESSION[$key] === $value;
    }
670438
public static function hasKeyFormat($value, AbstractValidator $keyValidator)
    {
        if ($value instanceof \ArrayObject) {
            $value = $value->getArrayCopy();
        }

        if ($value instanceof \SplFixedArray) {
            $value = $value->toArray();
        }

        $arrayKeys = \array_keys($value);
        $isValid   = true;

        foreach ($arrayKeys as $key) {
            $isValid = $isValid && $keyValidator->validate($key);
        }

        return $isValid;
    }
1078253
public function has($key , $value=null) {
		return CoreManager::has($this->path,$key,$value);
	}
1229004
public function isValid($value)
    {
        try {
            if (null === \json_decode($value, true)) {
                return $this->_error(self::INVALID);
            }
        } catch (\Exception $e) {
            return $this->_error(self::INVALID);
        }
        return true;
    }
1196515
protected function validateParameter($key, $value)
    {
        if (is_scalar($value)) {
            return true;
        }

        if (is_object($value)) {
            throw new IllegalTypeException(sprintf("Can't bind parameter %s with a callable", $key));
        }

        if (is_array($value)) {
            array_walk_recursive($value, function($item, $k) use($key) {
                if (!is_scalar($item)) {
                    throw new IllegalTypeException(
                        sprintf("Can't bind parameter, unauthorized value on key '%s' of '%s'", $k, $key));
                }
            });
        }

        return true;
    }
121083
public function update(string $key, $value): bool
    {
        if ($this->hasNot($key)) {
            return false;
        }

        $this->set($key, $value);

        return true;
    }
758628
public function verify($value) {
        if (!Factory::session()->has(self::SESSION_KEY)) {
            return false;
        }
        $data = Factory::session()->get(self::SESSION_KEY);
        if (!$data['sensitive'] && !is_numeric($value)) {
            $value = strtolower($value);
        }
        Factory::session()->delete(self::SESSION_KEY);
        return Hash::verify($value, $data['key']);
    }