Decrypts a string using the crypt_key configured in the config

@param string $string

@return string

@throws \BadMethodCallException  if the required mcrypt extension is not installed
168550
protected function decrypt($string)
	{
		// only if we want the cookie to be encrypted
		if ($this->config['cookie']['encrypt_cookie'])
		{
			// we require the mcrypt PECL extension for this
			if ( ! function_exists('mcrypt_decrypt'))
			{
				throw new \BadMethodCallException('The Session Cookie driver requires the PHP mcrypt extension to be installed.');
			}

			// create the encyption key
			$key = hash('SHA256', $this->config['cookie']['crypt_key'], true);

			// key the IV from the payload
			$iv = base64_decode(substr($string, 0, 22) . '==');
			$string = substr($string, 22);

			// decrypt the payload
			$string = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, base64_decode($string), MCRYPT_MODE_CBC, $iv), "\0\4");

			// split the hash from the payload
			$hash = substr($string, -32);
			$string = substr($string, 0, -32);

			// double-check it wasn't tampered with
			if (md5($string) != $hash)
			{
				return false;
			}
		}

		return $string;
	}
763530
private function decrypt($string = "")
    {
        $key = $this->config->get('gateway.asanpardakht.key');
        $iv = $this->config->get('gateway.asanpardakht.iv');

        try {

            $soap = new SoapClient("https://services.asanpardakht.net/paygate/internalutils.asmx?WSDL");
            $params = array(
                'aesKey' => $key,
                'aesVector' => $iv,
                'toBeDecrypted' => $string
            );

            $response = $soap->DecryptInAES($params);
            return $response->DecryptInAESResult;

        } catch (\SoapFault $e) {
            return "";
        }
    }
815556
public static function decode(string $string)
    {
        $content = json_decode($string, true);

        self::throwOnError();

        return $content;
    }
597764
public static function encrypt($string, $hash = false)
    {
        /**
         * if empty values return null
         */
        if (!$string) {
            return null;
        }
        /**
         * Using Alternative Encryption
         * if mCrypt not loaded
         */
        if (! extension_loaded('mCrypt')) {
            return static::altEncrypt($string, $hash);
        }

        /**
         * ------------------------------------
         * Safe Sanitized hash
         * ------------------------------------
         */
        (is_null($hash) || $hash === false) && $hash = '';
        // safe is use array or object as hash
        $hash      = Util::maybeSerialize($hash);

        /**
         * ------------------------------------
         * Set Key
         * ------------------------------------
         */
        $key       = pack('H*', sha1(sha256::hash($hash)));
        /**
         * pad to 24 length
         * on PHP 5.5 + need keylength 16, 24 or 32
         */
        $key       = str_pad($key, 24, "\0", STR_PAD_RIGHT);

        /**
         * create array as content
         * this is for great opinion that values has already encrypted
         * to easily check values
         */
        $string    = serialize(array('mcb' => $string));

        /**
         * ------------------------------------
         * Doing encryption
         * ------------------------------------
         */
        $iv_size   = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
        $iv        = mcrypt_create_iv($iv_size, MCRYPT_RAND);
        $crypt_text = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string, MCRYPT_MODE_ECB, $iv);

        // freed the memory
        unset($string, $key, $iv);
        // save as bse64 encode safe
        $crypt_text = trim(Util::safeBase64Encode($crypt_text));

        /**
         * ------------------------------------
         * Inject Result of with sign
         * ------------------------------------
         */
        if (strlen($crypt_text) > 10) {
            return substr_replace($crypt_text, '_mCb=', 10, 0);
        } else {
            return substr_replace($crypt_text, '_mCb=', 2, 0);
        }
    }
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
        );
    }
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])
                ));
        }


    }
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");
    }
1052737
public function encrypt($string)
    {
        $td = mcrypt_module_open($this->cypher, '', $this->mode, '');
        $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), mcrypt_RAND);
        mcrypt_generic_init($td, $this->key, $iv);
        $encrypted = mcrypt_generic($td, $string);
        mcrypt_generic_deinit($td);

        return $iv.$encrypted;
    }
447705
public function decryptToken(string $token)
    {
        $tokenData = false;
        $encrypted = base64_decode($token);

        if ($encrypted) {
            $serialized = Security::decrypt($encrypted, Configure::read('Security.cryptKey'));
            $tokenData = unserialize($serialized);
        }

        return $tokenData;
    }
1125172
public function encrypt($string, $key)
    {
        $string = "ox{$string}id";

        $key = $this->_formKey($key, $string);

        $string = $string ^ $key;
        $string = base64_encode($string);
        $string = str_replace("=", "!", $string);

        return "ox_$string";
    }
31136
public function encrypt($string)
  {
    $string = trim($string);
    $encryp = "";
    $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->encipher($xl, $xr);
      $encryp .= pack("N2", $xl, $xr);
    }

    return base64_encode($encryp);
  }
919175
public static function stringToKey(string $string): int {
        $key = 0;
        for ($i = 0; $i < \strlen($string); $i++) {
            $char = $string[$i];
            $key += \ord($char);
        }
        return $key;
    }
1008381
public static function str_to_hex($string) {
        $hex = '';

        for ($i = 0; $i < strlen($string); $i++) {
            $hex .= dechex(ord($string[$i]));
        }

        return $hex;
    }
218191
public static function decode($string)
    {
        if (!is_string($string)) {
            throw new \InvalidArgumentException(sprintf(
                'Accept only string argument but got: "%s"',
                is_object($string) ? get_class($string) : gettype($string)
            ));
        }

        // PHP7 fix - empty string and null cause syntax error
        if (empty($string)) {
            return null;
        }

        $decoded = json_decode($string, true);
        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new \InvalidArgumentException(sprintf(
                'The malformed json given. Error %s and message %s',
                json_last_error(),
                json_last_error_msg()
            ));
        }

        return $decoded;
    }
837040
private static function encodeString($string)
    {
        // Note:
        // strlen() returns the number of bytes rather than the number of characters in a string.

        // Differentiate on the string length.
        if (strlen($string) < 32) {
            // fixstr
            $prefix = bindec(101) * 32 + strlen($string);
        } elseif (strlen($string) < pow(2, 8)) {
            // str 8
            $prefix = 0xd9 * 256 + strlen($string);
        } elseif (strlen($string) < pow(2, 16)) {
            // str 16
            $prefix = 0xda * 256 * 256 + strlen($string);
        } elseif (strlen($string) < pow(2, 32)) {
            // str 32
            $prefix = 0xdb * 256 * 256 * 256 * 256 + strlen($string);
        } else {
            throw new UnencodeableException('String to be encoded is too long', 4);
        }

        // Encode it and concatenate with all bytes of the string value.
        return pack('H*', dechex($prefix)) . $string;
    }
1074200
protected function encrypt($string)
    {
        $iv = mcrypt_create_iv(mcrypt_get_iv_size($this->cipher, $this->cipherMode), MCRYPT_RAND);

        return mcrypt_encrypt($this->cipher, $this->secretKey, $string, $this->cipherMode, $iv);
    }
67019
public static function decode($string)
    {
        return ($string === self::NULL) ? null : strtr($string, self::$decodeMap);
    }