Returns a encrypt expression
@param string $text text to encrypt or field name
@param string $decryptionKey
@param bool $quote use false if $text is a field name
@return string
492080
public function getDecryptExpression($text, $decryptionKey, $quote = false)
    {
        $quotedText = $quote ? DB::connection()->getPdo()->quote($text) : $text;
        $quotedDecryptKey = DB::connection()->getPdo()->quote($decryptionKey);
        return "pgp_sym_decrypt({$quotedText}::bytea, $quotedDecryptKey)";
    }
440474
def decrypt(text):
    ''
    crypt = EncryptionAlgorithm.new(_get_encryption_key())
    return crypt.decrypt(text).rstrip(ENCRYPT_PAD_CHARACTER)
1336371
public static function decrypt($ciphertext, PrivateKey $rsaPrivateKey)
    {
        $split = explode(self::SEPARATOR, $ciphertext);
        if (\count($split) !== 4) {
            throw new InvalidCiphertextException('Invalid ciphertext message');
        }
        if (!\hash_equals($split[0], self::VERSION_TAG)) {
            throw new InvalidCiphertextException('Invalid version tag');
        }
        $checksum = \substr(
            \hash('sha256', implode('$', array_slice($split, 0, 3))),
            0,
            16
        );
        if (!\hash_equals($split[3], $checksum)) {
            throw new InvalidChecksumException('Invalid checksum');
        }

        $rsaCipher = Base64::decode($split[1]);
        $rsaPlain = self::rsaDecrypt(
            $rsaCipher,
            $rsaPrivateKey
        );
        $symmetricKey = hash_hmac(
            'sha256',
            $rsaCipher,
            $rsaPlain,
            true
        );

        $key = self::defuseKey($symmetricKey);
        return Crypto::decrypt(
            Base64::decode($split[2]),
            $key,
            true
        );
    }
1138314
private function decryptBlock($input, $key)
    {
        if (!$input && !$key) {
            return '';
        }

        $this->prepareCipher($key);
        $result = mdecrypt_generic($this->mcrypt, $input);
        mcrypt_generic_deinit($this->mcrypt);

        return $result;
    }
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;
    }
388712
public static function decryptString( $text, $salt, $urlDecode = false )
    {
        $_key = sha1( $salt, true );

        // PHP v5.6+ no longer pads strings with nulls for optimal length.
        // This replicates the missing feature.
        if ( version_compare( PHP_VERSION, '5.6.0', '>=' ) )
        {
            // sha1 hashes are always 20 characters. 24 is required.
            $_key .= "\0\0\0\0";
        }

        return trim(
            \mcrypt_decrypt(
                MCRYPT_RIJNDAEL_256,
                $_key,
                \base64_decode( $urlDecode ? urldecode( $text ) : $text ),
                MCRYPT_MODE_ECB,
                \mcrypt_create_iv( \mcrypt_get_iv_size( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB ), MCRYPT_RAND )
            )
        );
    }
967663
public function encrypt($text, $key)
    {
        $ivSize = mcrypt_enc_get_block_size($this->_mcrypt);
        $encryptKey = md5($key, true);

        /** @noinspection CryptographicallySecureRandomnessInspection */
        $iv = mcrypt_create_iv($ivSize, MCRYPT_DEV_URANDOM);

        mcrypt_generic_init($this->_mcrypt, $encryptKey, $iv);

        return $iv . mcrypt_generic($this->_mcrypt, pack('N', strlen($text) + 16) . $text . md5($text, true));
    }
658771
public String decrypt(String text, PrivateKey key) throws MangooEncryptionException {
        Objects.requireNonNull(text, Required.ENCRYPTED_TEXT.toString());
        Objects.requireNonNull(text, Required.PRIVATE_KEY.toString());
        
        String decrypt = null;
        try {
            byte[] dectyptedText = decrypt(decodeBase64(text), key);
            decrypt = new String(dectyptedText, StandardCharsets.UTF_8);
        } catch (MangooEncryptionException e) {
            throw new MangooEncryptionException("Failed to decrypt encrypted text with private key", e);
        }

        return decrypt;
    }
1286914
function decrypt($ciphertext)
    {
        if ( CRYPT_AES_MODE == CRYPT_AES_MODE_MCRYPT ) {
            $changed = $this->changed;
            $this->_mcryptSetup();
            /*
            if ($this->mode == CRYPT_AES_MODE_CTR) {
                $iv = $this->decryptIV;
                $xor = mcrypt_generic($this->enmcrypt, $this->_generate_xor(strlen($ciphertext), $iv));
                $plaintext = $ciphertext ^ $xor;
                if ($this->continuousBuffer) {
                    $this->decryptIV = $iv;
                }
                return $plaintext;
            }
            */
            if ($this->mode == 'ncfb') {
                if ($changed) {
                    $this->ecb = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, '');
                    mcrypt_generic_init($this->ecb, $this->key, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
                }

                if (strlen($this->debuffer)) {
                    $plaintext = $ciphertext ^ substr($this->decryptIV, strlen($this->debuffer));

                    $this->debuffer.= substr($ciphertext, 0, strlen($plaintext));
                    if (strlen($this->debuffer) == 16) {
                        $this->decryptIV = $this->debuffer;
                        $this->debuffer = '';
                        mcrypt_generic_init($this->demcrypt, $this->key, $this->decryptIV);
                    }
                    $ciphertext = substr($ciphertext, strlen($plaintext));
                } else {
                    $plaintext = '';
                }

                $last_pos = strlen($ciphertext) & 0xFFFFFFF0;
                $plaintext.= $last_pos ? mdecrypt_generic($this->demcrypt, substr($ciphertext, 0, $last_pos)) : '';

                if (strlen($ciphertext) & 0xF) {
                    if (strlen($plaintext)) {
                        $this->decryptIV = substr($ciphertext, $last_pos - 16, 16);
                    }
                    $this->decryptIV = mcrypt_generic($this->ecb, $this->decryptIV);
                    $this->debuffer = substr($ciphertext, $last_pos);
                    $plaintext.= $this->debuffer ^ $this->decryptIV;
                }

                return $plaintext;
            }

            if ($this->paddable) {
                // we pad with chr(0) since that's what mcrypt_generic does.  to quote from http://php.net/function.mcrypt-generic :
                // "The data is padded with "\0" to make sure the length of the data is n * blocksize."
                $ciphertext = str_pad($ciphertext, (strlen($ciphertext) + 15) & 0xFFFFFFF0, chr(0));
            }

            $plaintext = mdecrypt_generic($this->demcrypt, $ciphertext);

            if (!$this->continuousBuffer) {
                mcrypt_generic_init($this->demcrypt, $this->key, $this->iv);
            }

            return $this->paddable ? $this->_unpad($plaintext) : $plaintext;
        }

        return parent::decrypt($ciphertext);
    }
1126130
protected function _encrypt($decrypted = []) {
		$vector = $this->_config['vector'];
		$secret = $this->_hashSecret($this->_config['secret']);

		mcrypt_generic_init(static::$_resource, $secret, $vector);
		$encrypted = mcrypt_generic(static::$_resource, serialize($decrypted));
		mcrypt_generic_deinit(static::$_resource);

		return base64_encode($encrypted) . base64_encode($vector);
	}
566552
protected function decrypt($key, $text)
    {
        $td = mcrypt_module_open('blowfish', '', 'ecb', '');
        $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
        mcrypt_generic_init($td, $key , $iv);

        $data = mdecrypt_generic($td, $text);
        mcrypt_generic_deinit($td);
        mcrypt_module_close($td);

        $data = $this->pkcs5_unpad($data);

        return $data;
    }
888055
public static function decrypt($text)
    {
        if (function_exists('mcrypt_decrypt')) {
            $iv_size = mcrypt_get_iv_size(MCRYPT_XTEA, MCRYPT_MODE_ECB);
            $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
            $len = mcrypt_get_key_size(MCRYPT_XTEA, MCRYPT_MODE_ECB);

            /** @var \Concrete\Core\Config\Repository\Repository $config */
            $config = \Core::make('config/database');
            $text = trim(mcrypt_decrypt(MCRYPT_XTEA, substr($config->get('concrete.security.token.encryption'), 0, $len), base64_decode($text), MCRYPT_MODE_ECB, $iv));
        }

        return $text;
    }
1145311
public static function decrypt(
        string $cipherText,
        string $key,
        string $ad = '',
        string $format = null,
        $password = false
    ): string {
        $cipherText = self::toRaw($cipherText, $format);
        if ($cipherText === false) {
            throw new CryptoException('Ciphertext has invalid base64 encoding.');
        }

        if (\mb_strlen($cipherText, '8bit') < self::MINIMUM_CIPHERTEXT_SIZE) {
            throw new CryptoException('Ciphertext is too short.');
        }

        // Get and check the version header.
        $header = \mb_substr($cipherText, 0, self::HEADER_VERSION_SIZE, '8bit');
        if ($header !== self::CURRENT_VERSION) {
            throw new CryptoException('Bad version header.');
        }

        // Get the salt.
        $salt = \mb_substr(
            $cipherText,
            self::HEADER_VERSION_SIZE,
            self::SALT_BYTE_SIZE,
            '8bit'
        );
        if ($salt === false) {
            throw new CryptoException('Environment is broken');
        }

        // Get the IV.
        $iv = \mb_substr(
            $cipherText,
            self::HEADER_VERSION_SIZE + self::SALT_BYTE_SIZE,
            self::BLOCK_BYTE_SIZE,
            '8bit'
        );
        if ($iv === false) {
            throw new CryptoException('Environment is broken');
        }

        // Get the HMAC.
        $hmac = \mb_substr(
            $cipherText,
            \mb_strlen($cipherText, '8bit') - self::MAC_BYTE_SIZE,
            self::MAC_BYTE_SIZE,
            '8bit'
        );
        if ($hmac === false) {
            throw new CryptoException('Environment is broken');
        }

        // Get the actual encrypted ciphertext.
        $encrypted = \mb_substr(
            $cipherText,
            self::HEADER_VERSION_SIZE + self::SALT_BYTE_SIZE +
            self::BLOCK_BYTE_SIZE,
            \mb_strlen($cipherText, '8bit') - self::MAC_BYTE_SIZE - self::SALT_BYTE_SIZE -
            self::BLOCK_BYTE_SIZE - self::HEADER_VERSION_SIZE,
            '8bit'
        );
        if ($encrypted === false) {
            throw new CryptoException('Environment is broken');
        }
        // Derive the separate encryption and authentication keys from the key
        // or password, whichever it is.
        [$authKey, $encryptKey] = self::deriveKeys($key, $salt, $password);

        if (false === \hash_equals($hmac,
                \hash_hmac(self::HASH_TYPE, $header . $salt . $iv . $encrypted, $authKey, true))
        ) {
            throw new CryptoException('Integrity check failed.');
        }

        $ad = self::getAd($ad);

        if (self::$sodium) {
            $plaintext = \sodium_crypto_aead_aes256gcm_decrypt($encrypted, $ad, $iv, $encryptKey);
        } else {
            $tag = \mb_substr($encrypted, -self::TAG_BYTE_SIZE, null, '8bit');
            $encrypted = \mb_substr($encrypted, 0, -self::TAG_BYTE_SIZE, '8bit');

            $plaintext = \openssl_decrypt(
                $encrypted,
                self::CIPHER_METHOD,
                $encryptKey,
                \OPENSSL_RAW_DATA,
                $iv, $tag, $ad
            );
        }

        if ($plaintext === false) {
            throw new CryptoException('Decrypt failed.');
        }

        return $plaintext;
    }
1017819
function decrypt($ciphertext)
    {
        $this->_setup();

        if ($this->paddable) {
            // we pad with chr(0) since that's what mcrypt_generic does.  to quote from http://php.net/function.mcrypt-generic :
            // "The data is padded with "\0" to make sure the length of the data is n * blocksize."
            $ciphertext = str_pad($ciphertext, strlen($ciphertext) + ($this->block_size - strlen($ciphertext) % $this->block_size) % $this->block_size, chr(0));
        }

        $block_size = $this->block_size;
        $buffer = &$this->debuffer;
        $continuousBuffer = $this->continuousBuffer;
        $plaintext = '';
        switch ($this->mode) {
            case CRYPT_RIJNDAEL_MODE_ECB:
                for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
                    $plaintext.= $this->_decryptBlock(substr($ciphertext, $i, $block_size));
                }
                break;
            case CRYPT_RIJNDAEL_MODE_CBC:
                $xor = $this->decryptIV;
                for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
                    $block = substr($ciphertext, $i, $block_size);
                    $plaintext.= $this->_decryptBlock($block) ^ $xor;
                    $xor = $block;
                }
                if ($this->continuousBuffer) {
                    $this->decryptIV = $xor;
                }
                break;
            case CRYPT_RIJNDAEL_MODE_CTR:
                $xor = $this->decryptIV;
                if (!empty($buffer['ciphertext'])) {
                    for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
                        $block = substr($ciphertext, $i, $block_size);
                        $buffer['ciphertext'].= $this->_encryptBlock($this->_generate_xor($block_size, $xor));
                        $key = $this->_string_shift($buffer['ciphertext'], $block_size);
                        $plaintext.= $block ^ $key;
                    }
                } else {
                    for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
                        $block = substr($ciphertext, $i, $block_size);
                        $key = $this->_encryptBlock($this->_generate_xor($block_size, $xor));
                        $plaintext.= $block ^ $key;
                    }
                }
                if ($this->continuousBuffer) {
                    $this->decryptIV = $xor;
                    if ($start = strlen($ciphertext) % $block_size) {
                        $buffer['ciphertext'] = substr($key, $start) . $buffer['encrypted'];
                    }
                }
                break;
            case CRYPT_RIJNDAEL_MODE_CFB:
                if (!empty($buffer['ciphertext'])) {
                    $plaintext = $ciphertext ^ substr($this->decryptIV, strlen($buffer['ciphertext']));
                    $buffer['ciphertext'].= substr($ciphertext, 0, strlen($plaintext));
                    if (strlen($buffer['ciphertext']) == $block_size) {
                        $xor = $this->_encryptBlock($buffer['ciphertext']);
                        $buffer['ciphertext'] = '';
                    }
                    $start = strlen($plaintext);
                    $block = $this->decryptIV;
                } else {
                    $plaintext = '';
                    $xor = $this->_encryptBlock($this->decryptIV);
                    $start = 0;
                }

                for ($i = $start; $i < strlen($ciphertext); $i+=$block_size) {
                    $block = substr($ciphertext, $i, $block_size);
                    $plaintext.= $block ^ $xor;
                    if ($continuousBuffer && strlen($block) != $block_size) {
                        $buffer['ciphertext'].= $block;
                        $block = $xor;
                    } else if (strlen($block) == $block_size) {
                        $xor = $this->_encryptBlock($block);
                    }
                }
                if ($this->continuousBuffer) {
                    $this->decryptIV = $block;
                }
                break;
            case CRYPT_RIJNDAEL_MODE_OFB:
                $xor = $this->decryptIV;
                if (strlen($buffer)) {
                    for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
                        $xor = $this->_encryptBlock($xor);
                        $buffer.= $xor;
                        $key = $this->_string_shift($buffer, $block_size);
                        $plaintext.= substr($ciphertext, $i, $block_size) ^ $key;
                    }
                } else {
                    for ($i = 0; $i < strlen($ciphertext); $i+=$block_size) {
                        $xor = $this->_encryptBlock($xor);
                        $plaintext.= substr($ciphertext, $i, $block_size) ^ $xor;
                    }
                    $key = $xor;
                }
                if ($this->continuousBuffer) {
                    $this->decryptIV = $xor;
                    if ($start = strlen($ciphertext) % $block_size) {
                         $buffer = substr($key, $start) . $buffer;
                    }
                }
        }

        return $this->paddable ? $this->_unpad($plaintext) : $plaintext;
    }
12053
public static function encrypt($text)
    {
        if (function_exists('mcrypt_encrypt')) {
            $iv_size = mcrypt_get_iv_size(MCRYPT_XTEA, MCRYPT_MODE_ECB);
            $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
            $len = mcrypt_get_key_size(MCRYPT_XTEA, MCRYPT_MODE_ECB);

            /** @var \Concrete\Core\Config\Repository\Repository $config */
            $config = \Core::make('config/database');
            $text = base64_encode(mcrypt_encrypt(MCRYPT_XTEA, substr($config->get('concrete.security.token.encryption'), 0, $len), $text, MCRYPT_MODE_ECB, $iv));
        }

        return $text;
    }
48103
public String decrypt(String encrytedText) {
        Objects.requireNonNull(encrytedText, Required.ENCRYPTED_TEXT.toString());
        return decrypt(encrytedText, getSizedSecret(this.config.getApplicationSecret()));
    }
516012
@Override
  public String decrypt(String cipherText) {
    this.decryptionLock.lock();
    try{
      String decryptedValue = null;
      try {
        byte[] bytes = Base64.getDecoder().decode(cipherText);
        decryptedValue = new String(decryptCipher.doFinal(bytes), charset);
      } catch (UnsupportedEncodingException | IllegalBlockSizeException | BadPaddingException e) {
        logger.error("DefaultAESCBCCipher failed to decrypt text", e);
        throw new JsonDBException("DefaultAESCBCCipher failed to decrypt text", e);
      }
      return decryptedValue;
    } finally{
      this.decryptionLock.unlock();
    }
  }