Function decrypt

@author: 713uk13m <dev@nguyenanhung.com>
@time  : 2018-12-03 16:35

@param string $cipherText

@return string
503537
public function decrypt($cipherText = '')
    {
        $cipher = new \phpseclib\Crypt\AES();
        // could use AES::MODE_CBC
        // keys are null-padded to the closest valid size
        // longer than the longest key and it's truncated
        $cipher->setKeyLength($this->keyLength);
        $cipher->setKey($this->key);
//        $cipher->setPassword($this->key, 'pbkdf2', 'sha1', 'phpseclib/salt', 1000, 256 / 8);
        // the IV defaults to all-NULLs if not explicitly defined
        //$cipher->setIV('7014a0eb6d1611151a286c0ff4f2238f92c120d6');

        return $cipher->decrypt(base64_decode($cipherText));
    }
871491
protected function decrypt($string, $key){
        return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($string), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
    }
612413
public function decrypt($s)
	{
		$m = $this->load();
		if($m === null)
			return null;
		$padded = mdecrypt_generic($m, $s);
		$r = $this->_padding == parent::PADDING_PKCS7
			? self::removePKCS7Padding($padded,
				mcrypt_enc_get_block_size($m))
			: $padded;
		$this->unload($m);
		return $r;
	}
676596
public static function unseal(
        string $ciphertext,
        SealingSecretKey $secretKey
    ): string {
        $ephemeralPublicKey = \ParagonIE_Sodium_Core_Util::substr($ciphertext, 0, 32);

        $sharedSecret = static::keyExchange(
            $secretKey,
            new SealingPublicKey($ephemeralPublicKey),
            true,
            56
        );
        $sharedKey = \ParagonIE_Sodium_Core_Util::substr($sharedSecret, 0, 32);
        $nonce = \ParagonIE_Sodium_Core_Util::substr($sharedSecret, 32, 24);
        try {
            \ParagonIE_Sodium_Compat::memzero($sharedSecret);
        } catch (\Throwable $ex) {
        }

        $plaintext = \ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt(
            \ParagonIE_Sodium_Core_Util::substr($ciphertext, 32),
            $ephemeralPublicKey,
            $nonce,
            $sharedKey
        );
        if (!\is_string($plaintext)) {
            throw new InvalidMessageException('Incorrect message authentication tag');
        }
        return $plaintext;
    }
970652
public function decrypt($string)
    {

        $decrypted = "";
        $td = mcrypt_module_open($this->cypher, '', $this->mode, '');
        $ivsize = mcrypt_enc_get_iv_size($td);
        $iv = substr($string, 0, $ivsize);
        $string = substr($string, $ivsize);
        if ($iv) {
            mcrypt_generic_init($td, $this->key, $iv);
            $decrypted = mdecrypt_generic($td, $string);
        }

        return rtrim($decrypted);
    }
565258
public function decrypt($ciphertxt, $key = '', $ttl = 0)
    {
        if (empty($ciphertxt)) return $ciphertxt;
        if (empty($key)) $key = md5($this->key);
    
        $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.";
        $ikey ="-x6g6ZWm2G9g_vr0Bo.pOq3kRIxsZ6rm";
        $knum = 0;$i = 0;
        $tlen = @strlen($ciphertxt);
        while(isset($key{$i})) $knum +=ord($key{$i++});
        $ch1 = @$ciphertxt{$knum % $tlen};
        $nh1 = strpos($chars,$ch1);
        $ciphertxt = @substr_replace($ciphertxt,'',$knum % $tlen--,1);
        $ch2 = @$ciphertxt{$nh1 % $tlen};
        $nh2 = @strpos($chars,$ch2);
        $ciphertxt = @substr_replace($ciphertxt,'',$nh1 % $tlen--,1);
        $ch3 = @$ciphertxt{$nh2 % $tlen};
        $nh3 = @strpos($chars,$ch3);
        $ciphertxt = @substr_replace($ciphertxt,'',$nh2 % $tlen--,1);
        $nhnum = $nh1 + $nh2 + $nh3;
        $mdKey = substr(md5(md5(md5($key.$ch1).$ch2.$ikey).$ch3),$nhnum % 8,$knum % 8 + 16);
        $tmp = '';
        $j=0; $k = 0;
        $tlen = @strlen($ciphertxt);
        $klen = @strlen($mdKey);
        for ($i=0; $i<$tlen; $i++) {
            $k = $k == $klen ? 0 : $k;
            $j = strpos($chars,$ciphertxt{$i})-$nhnum - ord($mdKey{$k++});
            while ($j<0) $j+=64;
            $tmp .= $chars{$j};
        }
        $tmp = str_replace(array('-','_','.'), array('+','/','='), $tmp);
        $tmp = trim(base64_decode($tmp));
        
        if (preg_match("/\d{10}_/s", substr($tmp,0,11))){
            if ($ttl > 0 && (time() - substr($tmp,0,11) > $ttl)) {
                $tmp = null;
            }else{
                $tmp = substr($tmp, 11);
            }
        }
        return $tmp;
    }
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);
    }
1153503
public static function decrypt(
        string $ciphertext,
        SharedEncryptionKey $key
    ): string {
        $nonce = \ParagonIE_Sodium_Core_Util::substr($ciphertext, 0, 24);
        $result = \ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_decrypt(
            \ParagonIE_Sodium_Core_Util::substr($ciphertext, 24),
            $nonce,
            $nonce,
            $key->getString(true)
        );
        if (!\is_string($result)) {
            throw new InvalidMessageException('Message authentication failed.');
        }
        return $result;
    }
1285544
public function encrypt(string $decrypted): string {
        $status = openssl_private_encrypt($decrypted, $encrypted, $this);
        if(!$status) {
            throw new RuntimeException('Encrypt failed');
        }
        return $encrypted;
    }
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']);
    }
48103
public String decrypt(String encrytedText) {
        Objects.requireNonNull(encrytedText, Required.ENCRYPTED_TEXT.toString());
        return decrypt(encrytedText, getSizedSecret(this.config.getApplicationSecret()));
    }
912250
public function decrypt($string)
  {
    $string = base64_decode($string);
    $decryp = "";
    $length = strlen($string);
    $string .= str_repeat(chr(0), (8-($length%8))%8);

    for($i = 0; $i < $length; $i += 8)
    {
      list(,$xl,$xr) = unpack("N2", substr($string, $i, 8));
      $this->decipher($xl, $xr);
      $decryp .= pack("N2", $xl, $xr);
    }

    return trim($decryp);
  }
1278464
public function decrypt($input)
    {
        // Decode the IV + data
        $input = base64_decode($input);
        // Remove the IV
        $iv = substr($input, 0, Cipher::IV_SIZE);
        // Return Decrypted Data
        return openssl_decrypt(substr($input, Cipher::IV_SIZE), "AES-256-CBC", $this->secretKey, 0, $iv);
    }
1308880
public String decrypt(String cipherText) {
    byte[] original;
    try {
      // 设置解密模式为AES的CBC模式
      Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
      SecretKeySpec key_spec = new SecretKeySpec(aesKey, "AES");
      IvParameterSpec iv = new IvParameterSpec(Arrays.copyOfRange(aesKey, 0, 16));
      cipher.init(Cipher.DECRYPT_MODE, key_spec, iv);

      // 使用BASE64对密文进行解码
      byte[] encrypted = Base64.decodeBase64(cipherText);

      // 解密
      original = cipher.doFinal(encrypted);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    String xmlContent, from_appid;
    try {
      // 去除补位字符
      byte[] bytes = PKCS7Encoder.decode(original);

      // 分离16位随机字符串,网络字节序和AppId
      byte[] networkOrder = Arrays.copyOfRange(bytes, 16, 20);

      int xmlLength = bytesNetworkOrder2Number(networkOrder);

      xmlContent = new String(Arrays.copyOfRange(bytes, 20, 20 + xmlLength), CHARSET);
      from_appid = new String(Arrays.copyOfRange(bytes, 20 + xmlLength, bytes.length),
          CHARSET);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    // appid不相同的情况
    if (!from_appid.equals(appidOrCorpid)) {
      throw new RuntimeException("AppID不正确");
    }

    return xmlContent;

  }
467723
public function decrypt($encrypted) {
    return trim(
                mcrypt_decrypt(
                               MCRYPT_RIJNDAEL_256,
                               $this->password,
                               base64_decode($encrypted),
                               MCRYPT_MODE_ECB,
                               mcrypt_create_iv(
                                                mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB),
                                                MCRYPT_RAND
                                                )
                               )
                );
  }
1056997
public function decrypt( $text, $privateKey ) {
		$this->resetHome();

		$privateKeyId = $this->addKey( $privateKey );
		if ( !$privateKeyId ) {
			return false;
		}

		$cipherFile = $this->homeDir->makeTempFile( 'ciphertext-', $text );
		$clearFile = $this->homeDir->makeTempFile( 'cleartext-' );

		$args = array( '--decrypt', '--output', $clearFile, $cipherFile );
		$output = $this->call( $args, $retval );
		if ( $retval ) {
			$this->logger->warning( 'GPG encrypt call returned error',
				array( 'retval' => $retval, 'output' => $output ) );
			return false;
		}

		$clearText = file_get_contents( $clearFile );
		if ( !$clearText ) {
			$this->logger->warning( 'failed to load cleartext file' );
			return false;
		}

		return $clearText;
	}
1094167
public function decrypt($text, $key = null)
    {
        if (!function_exists('openssl_cipher_iv_length')) {
            throw new RuntimeException('openssl extension is required');
        }

        if ($key === null) {
            $decryptKey = $this->key;
        } else {
            $decryptKey = $key;
        }

        if (empty($decryptKey)) {
            throw new InvalidArgumentException('Decryption key cannot be empty');
        }

        $cipher = $this->cipher;
        $mode   = strtolower(substr($cipher, strrpos($cipher, '-') - strlen($cipher)));

        if (!in_array($cipher, openssl_get_cipher_methods(true))) {
            throw new UnexpectedValueException("Cipher algorithm is unknown [$cipher]");
        }

        $ivSize = openssl_cipher_iv_length($cipher);
        if ($ivSize > 0) {
            $blockSize = $ivSize;
        } else {
            $blockSize = openssl_cipher_iv_length(str_ireplace('-' . $mode, '', $cipher));
        }

        $decrypted = openssl_decrypt(substr($text, $ivSize), $cipher, $decryptKey, OPENSSL_RAW_DATA, substr($text, 0, $ivSize));

        $paddingType = $this->padding;

        if ($mode === 'cbc' || $mode === 'ecb') {
            return $this->unpadText($decrypted, $mode, $blockSize, $paddingType);
        }

        return $decrypted;
    }