Decrypt an attribute if required.

@param string $key
@param mixed  $value

@return mixed
553312
protected function doDecryptAttribute($key, $value)
    {
        if ($this->shouldEncrypt($key) && $this->isEncrypted($value)) {
            try {
                return $this->decryptedAttribute($value);
            } catch (DecryptException $e) {
            }
        }

        return $value;
    }
376335
public function setAttribute($key, $value)
    {
        if ($this->hasSetMutator($key)) {
            $method = 'set' .Str::studly($key) .'Attribute';

            return call_user_func(array($this, $method), $value);
        } else if (in_array($key, $this->getDates()) && $value) {
            $value = $this->fromDateTime($value);
        }

        $this->attributes[$key] = $value;
    }
199451
protected function getHtmlAttribValue($key, $value)
    {
        if (('on' == substr($key, 0, 2)) || ('constraints' == $key)) {
            // Don't escape event attributes; _do_ substitute double quotes with singles
            if (!is_scalar($value)) {
                // Non-scalar data should be cast to JSON first
                return Json::encode($value);
            }
            return $value;
        }
        
        if (is_array($value)) {
            return implode(' ', $value);
        }
        
        return $value;
    }
332428
public function setEncryptingAttribute($attribute, $value)
    {
        array_set($this->attributes, $attribute, $this->encrypt($value));
    }
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
        );
    }
430353
protected function cast_attribute( $key, $value ) {
		if ( is_null( $value ) ) {
			return $value;
		}

		switch ( $this->get_cast_type( $key ) ) {
			case 'int':
			case 'integer':
				return (int) $value;
			case 'real':
			case 'float':
			case 'double':
				return (float) $value;
			case 'string':
				return (string) $value;
			case 'array':
				return (array) $value;
			case 'bool':
			case 'boolean':
				return (bool) $value;
			default:
				return $value;
		}
	}
144778
public function setAttribute( $key, $value )
	{
		// First we will check for the presence of a mutator for the set operation
		// which simply lets the developers tweak the attribute as it is set on
		// the model, such as "json_encoding" an listing of data for storage.
		if ( $this->hasSetMutator( $key ) )
		{
			$method = 'set' . Str::studly( $key ) . 'Attribute';

			return $this->{$method}( $value );
		}

		// If an attribute is listed as a "date", we'll convert it from a DateTime
		// instance into a form proper for storage on the database tables using
		// the connection grammar's date format. We will auto set the values.
		elseif ( $value && ( in_array( $key, $this->getDates() ) || $this->isDateCastable( $key ) ) )
		{
			$value = $this->fromDateTime( $value );
		}

		if ( $this->isJsonCastable( $key ) && !is_null( $value ) )
		{
			$value = $this->asJson( $value );
		}

		$this->attributes[$key] = $value;

		return $this;
	}
550960
protected function _decode($value, $encrypt, $key)
    {
        if (!$encrypt) {
            return $this->_explode($value);
        }
        $this->_checkCipher($encrypt);
        $prefix = 'Q2FrZQ==.';
        $prefixLength = strlen($prefix);

        if (strncmp($value, $prefix, $prefixLength) !== 0) {
            return '';
        }

        $value = base64_decode(substr($value, $prefixLength), true);

        if ($value === false || $value === '') {
            return '';
        }

        if ($key === null) {
            $key = $this->_getCookieEncryptionKey();
        }
        if ($encrypt === 'rijndael') {
            $value = Security::rijndael($value, $key, 'decrypt');
        }
        if ($encrypt === 'aes') {
            $value = Security::decrypt($value, $key);
        }

        if ($value === false) {
            return '';
        }

        return $this->_explode($value);
    }
371657
public static function decrypt($data,$key){
        if(empty(self::$handler)){
            self::init();
        }
        $class  =   self::$handler;         
        return $class::decrypt($data,$key);
    }
692562
public function decrypt($decrypt, $key)
    {
        $inputParams = [
            'encrypt' => $decrypt,
            'key'     => $key,
        ];
        $this->debug->info(__FUNCTION__, 'Input Params: ' . json_encode($inputParams));
        $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB), MCRYPT_RAND);
        $this->debug->debug(__FUNCTION__, 'IV Key: ' . json_encode($iv));
        $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, pack("H*", $key), base64_decode($decrypt), MCRYPT_MODE_ECB, $iv);
        $this->debug->info(__FUNCTION__, 'decrypt Result: ' . json_encode($decrypted));

        return $decrypted;
    }
796957
protected function _decrypt($values, $mode, $key = null)
    {
        if (is_string($values)) {
            return $this->_decode($values, $mode, $key);
        }

        $decrypted = [];
        foreach ($values as $name => $value) {
            $decrypted[$name] = $this->_decode($value, $mode, $key);
        }

        return $decrypted;
    }
137905
public static function keyIsset($value, $key): bool
    {
        if (!static::isArrayAccessible($value)) {
            return false;
        }

        return isset($value[$key]);
    }
749750
private function fetchValueForKey($key, $value)
    {
        if (in_array($key, $this->getDates())) {
            return trim($value) === '' ? null : $value;
        }

        if (! $this->hasSetMutator($key)) {
            $value = $this->getAttribute($key);
        }

        if ($this->isJsonCastable($key) && ! is_null($value)) {
            $value = is_string($value) ? $this->getJsonCastValue($value) : $value;
        }

        return $value;
    }
1176959
public function decryptBinary(string $value, string $key): string
    {
        $iv = substr($value, 0, $this->ivLength);
        $encrypted = substr($value, $this->ivLength);
        $key = $this->hashKey($key);
        $opts = OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING;
        $ret = openssl_decrypt($encrypted, $this->cipher, $key, $opts, $iv);
        if ($ret === false) {
            throw new \Exception("decryption failed; ".openssl_error_string());
        }
        return $ret;
    }
361225
protected function castAttribute($key, $value)
    {
        if ($value === null) {
            return $value;
        }

        if ($this->getCastType($key) === 'serialize') {
            return $this->fromSerialize($value);
        }

        return parent::castAttribute($key, $value);
    }
1109932
public function setAttribute($key, $value)
    {
        if ($value !== null && $this->isSerializeCastable($key)) {
            $value = $this->asSerialize($value);
        }

        return parent::setAttribute($key, $value);
    }
1328321
public static function decrypt($data, $key = null)
    {
        is_null($key) && $key = Config::get('auth_key');
        return unserialize(self::cry($data, 2, $key));
    }