Authenticate and decrypt

@param string $data
@param string $key
@return string
512920
protected function decrypt($data, $key)
    {
        $hmac       = mb_substr($data, 0, 32, '8bit');
        $iv         = mb_substr($data, 32, 16, '8bit');
        $ciphertext = mb_substr($data, 48, null, '8bit');
        // Authentication
        $hmacNew = hash_hmac(
            'SHA256',
            $iv . $ciphertext,
            mb_substr($key, 32, null, '8bit'),
            true
        );
        if (! hash_equals($hmac, $hmacNew)) {
            throw new Exception\AuthenticationFailedException('Authentication failed');
        }
        // Decrypt
        return openssl_decrypt(
            $ciphertext,
            'AES-256-CBC',
            mb_substr($key, 0, 32, '8bit'),
            OPENSSL_RAW_DATA,
            $iv
        );
    }
278853
public function decrypt(string $data): string
    {
        $this->clearErrors();

        $vector = $this->getIV();
        if (empty($vector) === true) {
            $ivLength = $this->openSslIvLength($this->getMethod());
            $vector   = $this->readIV($data, $ivLength);
            $data     = $this->extractData($data, $ivLength);
        }

        if ($this->isUseAuthentication() === true) {
            $tagLength = $this->getTagLength();
            $tag       = $this->readTag($data, $tagLength);
            $data      = $this->extractData($data, $tagLength);

            $decrypted = $this->openSslDecryptAuthenticated(
                $data,
                $this->getMethod(),
                $this->getPassword(),
                $this->getOptions(),
                $vector,
                $this->getAdditionalAuthenticationData(),
                $tag
            );
        } else {
            $decrypted = $this->openSslDecrypt(
                $data,
                $this->getMethod(),
                $this->getPassword(),
                $this->getOptions(),
                $vector
            );
        }

        return $decrypted;
    }
38130
public static function decode(string $data, string $secret )
  {
    # Make a HASH of the secret
    $secret = openssl_digest($secret,'sha256');

    $b64 = static::base64url_decode($data);
    $ewt = json_decode($b64,true);

    $payload = openssl_decrypt($ewt['p'], $ewt['a'], $secret, 0, $ewt['i']);

    # Verify signature - if fail return null
    if ( strcasecmp(static::sign($payload,$secret,$ewt['h']),$ewt['s'])!=0) {
      return null;
    }

    return $payload;
  }
1088332
public static function encrypt($data, $key = self::KEY, $iv = self::IV)
    {
        return base64_encode(openssl_encrypt($data, self::MOD, $key, OPENSSL_RAW_DATA, $iv));
    }
834014
public function Decrypt($data, $key)
	{
		if ($data == null)
		{
			return null;
		}
		$iv = substr($data, 0, 16);
		$payload = substr($data, 16);
		return openssl_decrypt($payload, 'AES-256-CBC', base64_decode($key), OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $iv);
	}
222273
public static byte[] decryptBase64AES(byte[] data, byte[] key) {
        try {
            return decryptAES(Base64.getDecoder().decode(data), key);
        } catch (Exception e) {
            return null;
        }
    }
1297752
public static function decrypt(string $data, string $pass): string
    {
        return OpensslStatic::decrypt($data, $pass, static::CIPHER, static::CHKSUM);
    }
256685
public static function get(string $key): ?string
    {
        if (isset($_COOKIE) && array_key_exists($key, $_COOKIE)) {
            return Crypt::decrypt($_COOKIE[$key]);
        }

        return null;
    }
1339837
public function decryptMessage(string $key)
    {
        $message = $this->getMessage();
        if (empty($message[$key])) {
            return null;
        }

        return Support\AES::decrypt(
            base64_decode($message[$key], true), md5($this->app['config']->key), '', OPENSSL_RAW_DATA, 'AES-256-ECB'
        );
    }
991964
public static function decryptRsaPublic(string $data, string $publicKey, string $format = null): string
    {
        $data = self::toRaw($data, $format);
        $key = \openssl_pkey_get_public($publicKey);

        $decrypted = '';
        if (!\openssl_public_decrypt($data, $decrypted, $key, OPENSSL_PKCS1_OAEP_PADDING)) {
            throw new CryptoException('RSA public decrypt error: ' . openssl_error_string());
        }
        \openssl_pkey_free($key);

        return $decrypted;
    }
789290
public static function getDecoded($data, $key)
    {
        if (!Any::isArray($data)) {
            $data = self::decode($data);
        }

        return $data === false ? null : $data[$key];
    }
911148
public static byte[] decrypt(byte[] data, byte[] key) {
        checkNotNull(data);
        checkNotNull(key);
        checkArgument(key.length >= 5 && key.length <= 256);
        StreamCipher rc4 = new RC4Engine();
        rc4.init(false, new KeyParameter(key));
        byte[] decrypted = new byte[data.length];
        rc4.processBytes(data, 0, data.length, decrypted, 0);
        return decrypted;
    }
1266589
public function decrypt($data, $key = null, $iv = null)
    {
        $key = $key === null ? $this->privateKey : $key;

        if (strpos($data, ':') !== false) {
            list($hmac, $pbkdf2Salt, $ivFromData, $encrypted) = explode(':', $data);

            $hmac = base64_decode($hmac);
            $pbkdf2Salt = base64_decode($pbkdf2Salt);
            $ivFromData = base64_decode($ivFromData);
            $encrypted = base64_decode($encrypted);

            $iv = $iv ?: $ivFromData;

            $this->derivateSecureKeys($key, $pbkdf2Salt);

            $calculatedHmac = $this->hmac($pbkdf2Salt . $iv . $encrypted);

            if (!$this->equalHashes($calculatedHmac, $hmac)) {
                throw new \RuntimeException('HMAC ERROR: Invalid HMAC.');
            }
        } else {
            // For 3.1 and older legacy
            $data = base64_decode($data);

            if (!$iv) {
                $ivSize = $this->getIVSize();

                $iv = substr($data, 0, $ivSize);

                $encrypted = substr($data, $ivSize);
            } else {
                $ivSize = $this->getIVSize();

                if (substr($data, 0, $ivSize) === $iv) {
                    $encrypted = substr($data, $ivSize);
                } else {
                    $encrypted = $data;
                }
            }
        }

        $key = CryptHelper::repeatToLength($key, 24, true);

        // Decrypt the data.
        return trim($this->doDecrypt($encrypted, $key, $iv));
    }
749181
public function getAttribute(string $key)
    {
        $value = parent::getAttribute($key);

        if ($this->valid($key, $value)) {
            return decrypt($value);
        }

        return $value;
    }
363314
public static function decrypt($data = '', $key = ''): string
    {
        $key = md5(empty($key) ? \Yii::$app->getRequest()->cookieValidationKey : $key);
        $data = str_replace(['-', '_'], ['+', '/'], $data);
        $mod4 = strlen($data) % 4;
        if ($mod4) {
            $data .= substr('====', $mod4);
        }
        $data = base64_decode($data);
        $expire = substr($data, 0, 10);
        $data = substr($data, 10);
        
        if ($expire > 0 && $expire < time()) {
            return '';
        }
        $x = 0;
        $len = strlen($data);
        $l = strlen($key);
        $char = $str = '';
        
        for ($i = 0; $i < $len; $i++) {
            if ($x == $l) {
                $x = 0;
            }
            $char .= substr($key, $x, 1);
            $x++;
        }
        
        for ($i = 0; $i < $len; $i++) {
            if (ord(substr($data, $i, 1)) < ord(substr($char, $i, 1))) {
                $str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1)));
            } else {
                $str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1)));
            }
        }
        
        return base64_decode($str);
    }
1192498
public function decrypt($data, Key $key)
	{
		// Validate key.
		if ($key->type != $this->keyType)
		{
			throw new \InvalidArgumentException('Invalid key of type: ' . $key->type . '.  Expected ' . $this->keyType . '.');
		}

		// Decrypt the data.
		$decrypted = trim(mcrypt_decrypt($this->type, $key->private, $data, $this->mode, $key->public));

		return $decrypted;
	}
161261
public function decrypt($data, $key = null, $iv = null)
    {
        include_once __DIR__ . '/../lib/aes.class.php';

        return \AesCtr::decrypt(base64_decode($data), $key, $this->keyLength);
    }