{@inheritDoc}

@throws InvalidKeyException Will occur if you use the wrong password to
retrieve the data
434920
@Override
    public T read(Serializable id) throws InvalidKeyException {
        ensureOpen();

        String sql = "SELECT " + COLUMN_DATA + " FROM " + TABLE_NAME + " WHERE " + COLUMN_ID + " = ?";
        Cursor cursor = getReadableDatabase().rawQuery(sql, new String[]{id.toString()});
        cursor.moveToFirst();

        if (cursor.getCount() == 0) {
            return null;
        }

        try {
            byte[] encryptedData = cursor.getBlob(0);
            return cryptoEntityUtil.decrypt(encryptedData);
        } finally {
            cursor.close();
        }
    }
1320465
protected function isValidSenderAction(string $action): void
    {
        $allowedSenderAction = $this->getAllowedSenderAction();
        if (!\in_array($action, $allowedSenderAction, true)) {
            throw new InvalidKeyException(sprintf(
                'action must be either "%s".',
                implode(', ', $allowedSenderAction)
            ));
        }
    }
760880
private void initCipher(int mode) throws InvalidKeyException, InvalidAlgorithmParameterException
    {
        if (key != null)
        {
            if (params != null)
            {
                if (random != null)
                {
                    cipher.init(mode, key, params, random);
                }
                else
                {
                    cipher.init(mode, key, params);
                }
            }
            else if (spec != null)
            {
                if (random != null)
                {
                    cipher.init(mode, key, spec, random);
                }
                else
                {
                    cipher.init(mode, key, spec);
                }
            }
            else
            {
                if (random != null)
                {
                    cipher.init(mode, key, random);
                }
                else
                {
                    cipher.init(mode, key);
                }
            }
        }
        else
        {
            if (random != null)
            {
                cipher.init(mode, certificate, random);
            }
            else
            {
                cipher.init(mode, certificate);
            }
        }
    }
100425
public static function getKey(): string
    {
        $key = static::getConfig('application')->get('key');

        if ($key === null || $key === '') {
            throw new ApplicationException('The key \'key\' in application config is invalid; please set non-empty string there');
        }

        if ($key == '_____ENTERSomeRandomKeyHere_____') {
            throw new ApplicationException('Please configure key \'key\' in main application config, it can\'t be _____ENTERSomeRandomKeyHere_____');
        }

        if (strlen($key) > 32) {
            throw new ApplicationException('Please make sure your application key in application config is not longer then 32 chars');
        }

        return $key;
    }
1353382
public function getLanguageFileKey(string $fileName, string $key)
    {
        // Check the input file name
        if (!$this->checkFileName($fileName)) {
            throw new InvalidFileNameException("Input file name is not valid.");
        }

        return $this->translator->get("$fileName.$key");
    }
983290
public function decrypt($data, Key $key)
	{
		// Validate key.
		if ($key->type != 'simple')
		{
			throw new \InvalidArgumentException('Invalid key of type: ' . $key->type . '.  Expected simple.');
		}

		$decrypted = '';
		$tmp = $key->public;

		// Convert the HEX input into an array of integers and get the number of characters.
		$chars = $this->_hexToIntArray($data);
		$charCount = count($chars);

		// Repeat the key as many times as necessary to ensure that the key is at least as long as the input.
		for ($i = 0; $i < $charCount; $i = strlen($tmp))
		{
			$tmp = $tmp . $tmp;
		}

		// Get the XOR values between the ASCII values of the input and key characters for all input offsets.
		for ($i = 0; $i < $charCount; $i++)
		{
			$decrypted .= chr($chars[$i] ^ ord($tmp[$i]));
		}

		return $decrypted;
	}
152472
public function PreKeyRecord($id = null, $keyPair = null, $serialized = null) // [int id, ECKeyPair keyPair]
    {
        $this->structure = new Textsecure_();
        if ($serialized == null) {
            $this->structure->setId($id)->setPublicKey((string) $keyPair->getPublicKey()->serialize())->setPrivateKey((string) $keyPair->getPrivateKey()->serialize());
        } else {
            try {
                $this->structure->parseFromString($serialized);
            } catch (Exception $ex) {
                throw new Exception('Cannot unserialize PreKEyRecordStructure');
            }
        }
    }
949789
protected static function requireValue($data, $key)
    {
        if (isset($data[$key])) {
            return $data[$key];
        } else {
            throw new Exception\InvalidDataException("Required value for '$key' is missing");
        }
    }
134435
public function getConfig($key = '')
    {
        if (empty($key)) {
            return $this->_config;
        }

        if (!\array_key_exists($key, $this->_config)) {
            throw new InvalidException('Config key is not set: '.$key);
        }

        return $this->_config[$key];
    }
126489
function getKey(key, masterPassword) {
    var contents = getContents(masterPassword);
    if (contents[key] != undefined) return contents[key];
    else throw new Error(`Unable to find key '${key}' in password safe.`);
}
45573
public function getData()
    {
        // The application has the option of passing the query parameter
        // in, perhaps using its own middleware, or allowing Omnipay to
        // provide it.

        $crypt = $this->getCrypt() ?: $this->httpRequest->query->get('crypt');

        // Make sure we have a crypt parameter before trying to decrypt it.

        if (empty($crypt) || !is_string($crypt) || substr($crypt, 0, 1) !== '@') {
            throw new InvalidResponseException('Missing or invalid "crypt" parameter');
        }

        // Remove the leading '@' and decrypt the remainder into a query string.
        // An InvalidResponseException is thrown if the crypt parameter data is not
        // a hexadecimal string.

        $hexString = substr($crypt, 1);

        if (! preg_match('/^[0-9a-f]+$/i', $hexString)) {
            throw new InvalidResponseException('Invalid "crypt" parameter; not hexadecimal');
        }

        $queryString = openssl_decrypt(
            hex2bin($hexString),
            'aes-128-cbc',
            $this->getEncryptionKey(),
            OPENSSL_RAW_DATA,
            $this->getEncryptionKey()
        );

        parse_str($queryString, $data);

        // The result will be ASCII data only, being a very restricted set of
        // IDs and flags, so can be treated as UTF-8 without any conversion.

        return($data);
    }
227474
public function getConfig($key = '')
    {
        $config = $this->getParam('config');
        if (empty($key)) {
            return $config;
        }

        if (!\array_key_exists($key, $config)) {
            throw new InvalidException('Config key is not set: '.$key);
        }

        return $config[$key];
    }
1297320
public static function validateMultiple($keys)
    {
        foreach ($keys as $key) {
            if (!is_string($key) && !is_int($key)) {
                throw InvalidKeyException::forKey($key);
            }
        }
    }
870834
public function setPassword($password, $publicKeyByIp = true) {
		if($this->auth) {
			throw new \Exception('Password already defined');
		}
		$this->convertEncoding($password, self::CLIENT_ENCODING, $this->serverEncoding);
		$this->auth = new Auth($password, $publicKeyByIp);
		if($this->client) {
			$this->isAuthorized = $this->client->auth && $this->auth->isValidAuth($this->client->auth);
		}
	}
115707
private function storeInput($values)
    {
        $requiredKeys = [
            'subject',
            'account_id',
            'inbound_email_account_id',
            'email_address',
        ];

        foreach ($requiredKeys as $key)
        {
            if (!array_key_exists($key, $values))
            {
                throw new InvalidArgumentException("$key is a required key in the input array.");
            }
        }

        foreach ($values as $key => $value)
        {
            if ($value === null)
            {
                continue;
            }
            $function = ucwords(StringFormatter::camelCase($key));
            try {
                call_user_func([$this, "set$function"], $value);
            }
            catch (Exception $e)
            {
                continue;
            }
        }
    }
1153895
private function validateKey(string $key): void
    {
        $key_pattern = $this->cache->getOptions()->getKeyPattern();

        if ($key === '') {
            throw new InvalidKeyException('An empty key is not allowed');
        } elseif (!empty($key_pattern && !preg_match($key_pattern, $key))) {
            throw new InvalidKeyException(
                sprintf('The key "%s" does not match against pattern "%s"', $key, $key_pattern)
            );
        }
    }
1086171
protected function _setKeys($keys)
    {
        if (!is_array($keys)) {
            throw new Exception\InvalidArgumentException('Invalid options argument provided to filter');
        }

        foreach ($keys as $type => $key) {
            if (is_file($key) and is_readable($key)) {
                $file = fopen($key, 'r');
                $cert = fread($file, 8192);
                fclose($file);
            } else {
                $cert = $key;
                $key  = count($this->keys[$type]);
            }

            switch ($type) {
                case 'public':
                    $test = openssl_pkey_get_public($cert);
                    if ($test === false) {
                        throw new Exception\InvalidArgumentException("Public key '{$cert}' not valid");
                    }

                    openssl_free_key($test);
                    $this->keys['public'][$key] = $cert;
                    break;
                case 'private':
                    $test = openssl_pkey_get_private($cert, $this->passphrase);
                    if ($test === false) {
                        throw new Exception\InvalidArgumentException("Private key '{$cert}' not valid");
                    }

                    openssl_free_key($test);
                    $this->keys['private'][$key] = $cert;
                    break;
                case 'envelope':
                    $this->keys['envelope'][$key] = $cert;
                    break;
                default:
                    break;
            }
        }

        return $this;
    }