@param string $cipherText
@param string $key

@return string

@throws InvalidHmacException
@throws InvalidCipherTextException
432737
private function decrypt($cipherText, $key)
    {
        $data = base64_decode($cipherText);

        $ivSize = openssl_cipher_iv_length(self::OPENSSL_METHOD);

        $iv = substr($data, 0, $ivSize);
        $hmac = substr($data, $ivSize, self::HMAC_LENGTH);
        $rawCipherText = substr($data, $ivSize + self::HMAC_LENGTH);

        $plainText = @openssl_decrypt($rawCipherText, self::OPENSSL_METHOD, $key, OPENSSL_RAW_DATA, $iv);

        if (empty($plainText)) {
            throw new InvalidCipherTextException();
        }

        $calculatedHmac = hash_hmac('sha256', $rawCipherText, $key, true);

        if ($hmac !== $calculatedHmac) {
            throw new InvalidHmacException();
        }

        return $plainText;
    }
978382
public static function decrypt($message, $key, $encoded = false)
    {
        if ($encoded) {
            $message = base64_decode($message, true);
            if ($message === false) {
                throw new Exception('Encryption failure');
            }
        }

        $nonceSize = openssl_cipher_iv_length(self::METHOD);
        $nonce = mb_substr($message, 0, $nonceSize, '8bit');
        $ciphertext = mb_substr($message, $nonceSize, null, '8bit');

        $plaintext = openssl_decrypt(
            $ciphertext,
            self::METHOD,
            $key,
            OPENSSL_RAW_DATA,
            $nonce
        );

        return $plaintext;
    }
207948
public static function valid($key, $cipher)
    {
        $keyLength = mb_strlen($key, '8bit');

        if (static::SUPPORTED_CIPHER_32_LENGTH === $keyLength
            && $cipher === static::SUPPORTED_CIPHER_32) {
            return true;
        }

        if (static::SUPPORTED_CIPHER_16_LENGTH == $keyLength
            && $cipher === static::SUPPORTED_CIPHER_16) {
            return true;
        }

        return false;
    }
236679
public function decrypt($string, $key = null)
    {
        if (null === $key) {
            $key = $this->getEncryptKey();
        }

        $cipherText = base64_decode($string);
        $ivSize     = $this->getMsCryptIvSize();

        $ivDec = substr($cipherText, 0, $ivSize);

        $cipherText = substr($cipherText, $ivSize);

        return mcrypt_decrypt(
            $this->getMcryptCipher(),
            $key,
            $cipherText,
            $this->getMcryptMode(),
            $ivDec
        );
    }
545245
public function decrypt($crypttext, $key = null) {
        if(null !== $key) {
            $this->_key = md5($key);
        }

        $crypttext = base64_decode($crypttext);
        $plaintext = '';
        $td        = mcrypt_module_open($this->_cypher, '', self::MODE, '');
        $ivsize    = mcrypt_enc_get_iv_size($td);
        $iv        = substr($crypttext, 0, $ivsize);
        $crypttext = substr($crypttext, $ivsize);
        if ($iv) {
            mcrypt_generic_init($td, $this->_key, $iv);
            $plaintext = mdecrypt_generic($td, $crypttext);
        }
        return trim($plaintext);
    }
575854
static public function encrypt($plaintextFileName, $ciphertextFileName, $key_name = null) {
        $kms = self::getService();
        if (is_null($key_name)) {
            $key_name = self::getDefaultKeyName();
        }

        // Use the KMS API to encrypt the text.
        $encoded = base64_encode(file_get_contents($plaintextFileName));
        $request = new \Google_Service_CloudKMS_EncryptRequest();
        $request->setPlaintext($encoded);
        $response = $kms->projects_locations_keyRings_cryptoKeys->encrypt(
            $key_name,
            $request
        );

        // Write the encrypted text to a file.
        file_put_contents($ciphertextFileName, base64_decode($response['ciphertext']));
        Util::cmdline("\tSaved encrypted text to $ciphertextFileName with key $key_name");
        return true;
    }
1338514
static public function decrypt($ciphertextFileName, Config $config = null) {
        // Instantiate the client, authenticate, and add scopes.
        $kms = self::getService();
        $name = self::getDefaultKeyName($config);
        // Use the KMS API to decrypt the text.
        $ciphertext = base64_encode(file_get_contents($ciphertextFileName));
        $request = new \Google_Service_CloudKMS_DecryptRequest();
        $request->setCiphertext($ciphertext);
        $response = $kms->projects_locations_keyRings_cryptoKeys->decrypt(
            $name,
            $request
        );
        return base64_decode($response['plaintext']);
    }
1137896
public function decrypt(string $ciphertext, string $key): string
    {
        $numMatches = preg_match_all('%^ENC\[([^,]+),(.*)\]$%', $ciphertext, $matches);
        if (0 == $numMatches) {
            throw new Exception\RuntimeException(sprintf(
                "\$ciphertext must be in the format ENC[\$encryptionType,\$ciphertext].\n"
                . "Provided ciphertext: %s",
                $ciphertext
            ));
        }

        $encryptionType = $matches[1][0];
        $ciphertext = $matches[2][0];

        switch ($encryptionType) {
            case self::ENCRYPTION_TYPE_DEFUSE_PHP_ENCRYPTION:
                $key = Key::loadFromAsciiSafeString($key);
                return Crypto::decrypt($ciphertext, $key);

            default:
                throw new Exception\RuntimeException(sprintf(
                    'Unsupported encryption type "%s". Supported encryption types: "%s".',
                    $encryptionType,
                    implode('", "', [self::ENCRYPTION_TYPE_DEFUSE_PHP_ENCRYPTION])
                ));
        }


    }
256685
public static function get(string $key): ?string
    {
        if (isset($_COOKIE) && array_key_exists($key, $_COOKIE)) {
            return Crypt::decrypt($_COOKIE[$key]);
        }

        return null;
    }
917233
public function encrypt($plaintext, $key = null) {
        if(null !== $key) {
            $this->_key = md5($key);
        }

        $td = mcrypt_module_open($this->_cypher, '', self::MODE, '');
        $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
        mcrypt_generic_init($td, $this->_key, $iv);
        $crypttext = mcrypt_generic($td, $plaintext);
        mcrypt_generic_deinit($td);
        return base64_encode($iv . $crypttext);
    }
6208
public function decrypt($cipher_string, $cipher_key)
    {
        $cipher_key = $this->_genKey($cipher_key);

        $hmacSize = 64;
        $hmacString = mb_substr($cipher_string, 0, $hmacSize, "8bit");
        $cipher_text = mb_substr($cipher_string, $hmacSize, null, "8bit");

        if(!$this->validHmac($hmacString, $this->_genHmac($cipher_text, $cipher_key)))
            return false;

        $ivSize = openssl_cipher_iv_length('AES-256-CBC');
        $iv = mb_substr($cipher_text, 0, $ivSize, '8bit');
        $cipher_text = mb_substr($cipher_text, $ivSize, null, '8bit');

        return openssl_decrypt($cipher_text, 'AES-256-CBC', $cipher_key, OPENSSL_RAW_DATA, $iv);
    }
1328919
static function ensureKey(string $key)
    {
        if (!self::hasKey($key)) {
            throw new InvalidKeyException(sprintf(
                'The key "%s" is not defined in enum class "%s", known keys: %s',
                $key,
                static::class,
                implode(', ', self::getKeys())
            ));
        }
    }
1224943
public static String encrypt(String key, String plainText) {
        SecretKey secret = new SecretKeySpec(Base64.decodeBase64(key.getBytes(StandardCharsets.UTF_8)), "AES");
        return encryptBouncyCastle(secret, plainText);
    }
302771
public function encrypt($plaintext, $key)
	{
		// Set up encryption parameters.
		$inputData = cryptoHelpers::convertStringToByteArray($plaintext);
		$keyAsNumbers = cryptoHelpers::toNumbers(bin2hex($key));
		$keyLength = count($keyAsNumbers);
		$iv = cryptoHelpers::generateSharedKey(16);

		$encrypted = AES::encrypt(
			$inputData,
			AES::modeOfOperation_CBC,
			$keyAsNumbers,
			$keyLength,
			$iv
		);

		$retVal = $encrypted['originalsize'] . self::SEPARATOR_CRYPTO_PARTS
			. cryptoHelpers::toHex($iv) . self::SEPARATOR_CRYPTO_PARTS
			. cryptoHelpers::toHex($encrypted['cipher']);

		return self::IDENTIFIER . self::SEPARATOR_ALGORITHM . $retVal;
	}
266789
public static function decrypt(string $cipherText, string $key, string $iv, int $option = OPENSSL_RAW_DATA, $method = null): string
    {
        self::validateKey($key);
        self::validateIv($iv);

        return openssl_decrypt($cipherText, $method ?: self::getMode($key), $key, $option, $iv);
    }
1280381
public static function crypt(string $str, string $key): string
    {
        $s = self::initializeState($key);
        $i = $j = 0;
        $res = '';
        $size = Str::strlen($str);
        for ($y = 0; $y < $size; $y++) {
            $i = ($i + 1) % 256;
            $j = ($j + $s[$i]) % 256;
            $x = $s[$i];
            $s[$i] = $s[$j];
            $s[$j] = $x;
            $res .= $str[$y] ^ \chr($s[($s[$i] + $s[$j]) % 256]);
        }

        return $res;
    }
572762
private function encrypt($plaintext, $key)
    {
        $ivSize = openssl_cipher_iv_length(self::OPENSSL_METHOD);
        $iv = openssl_random_pseudo_bytes($ivSize);

        $rawCipherText = openssl_encrypt(
            $plaintext,
            self::OPENSSL_METHOD,
            $key,
            OPENSSL_RAW_DATA,
            $iv
        );

        $hmac = hash_hmac('sha256', $rawCipherText, $key, true);

        return base64_encode($iv . $hmac . $rawCipherText);
    }