验证返回数据签名

@param $contents
@return array|bool
195549
public function verifyReturn($contents)
    {
        $contents = Helper::decodeUnicode($contents);
        // 解析字符串
        $result = (array)simplexml_load_string($contents, 'SimpleXMLElement', LIBXML_NOCDATA);
        if (!$this->sign->verifySign($result, $this->config['key'])) {
            return false;
        }

        return $result;
    }
269916
protected function replaceAppClass($contents)
    {
        $modified = str_replace(
            'Illuminate\Foundation\Application',
            'Shpasser\GaeSupportL5\Foundation\Application',
            $contents);

        if ($contents !== $modified) {
            $this->myCommand->info('Replaced the application class in "bootstrap/app.php".');
        }

        return $modified;
    }
373913
public function sign($content) {
        if (is_array($content)) {
            $content = $this->getSignContent($content);
        }
        if ($this->getSignType() == self::MD5) {
            return md5($content.$this->public_key);
        }
        $priKey = $this->private_key;
        $res = "-----BEGIN RSA PRIVATE KEY-----\n" .
            wordwrap($priKey, 64, "\n", true) .
            "\n-----END RSA PRIVATE KEY-----";
        if (self::RSA2 == $this->getSignType()) {
            openssl_sign($content, $sign, $res, OPENSSL_ALGO_SHA256);
        } else {
            openssl_sign($content, $sign, $res);
        }
        if (is_resource($res)) {
            openssl_free_key($res);
        }
        return base64_encode($sign);
    }
581308
public function changeShortEchoTag($content = '')
    {
        $content = str_replace(["\r\n", "\r"], "\n", $content); //统一换行符
        if ($this->options['alternativeSyntax']) {
            $finders = ['!<\?php\s+/\*ECHO\*/echo!m', '!;/\*ENDECHO\*/\s+\?>!m'];
            $content = preg_replace($finders, ['<?=', '?>'], $content);
            $content = str_replace(['/*ECHO*/', '/*ENDECHO*/'], '', $content);
        }
        return $content;
    }
1320501
public function replace($contents, array $variables = [], array $replacements = [])
    {
        $contents = str_replace($variables, $replacements, $contents);
        $contents = preg_replace('/^ +$/m', '', $contents);

        return $contents;
    }
51029
private function extractSignedContent($content)
    {
        $signature = substr($content, -40);

        if (substr($content, -43, 3) == self::VALUE_SEPARATOR . '_=' &&
            $signature == sha1(substr($content, 0, -40) . SettingsPiwik::getSalt())
        ) {
            // strip trailing: VALUE_SEPARATOR '_=' signature"
            return substr($content, 0, -43);
        }

        return false;
    }
1199836
function getFilename(){
		if($content_disposition = $this->getHeaderValue("Content-Disposition")){
			if(preg_match('/filename="(.*?)"/',$content_disposition,$matches)){
				return $matches[1];
			}
		}
		if(preg_match("/([^\\/?]+)(\\?.*|)$/",$this->_Uri,$matches)){
			return $matches[1];
		}
	}
896202
public function compactContents($file, $contents)
    {
        foreach ($this->compactors as $compactor) {
            /** @var $compactor CompactorInterface */
            if ($compactor->supports($file)) {
                $contents = $compactor->compact($contents);
            }
        }

        return $contents;
    }
371636
public static function parseLines($content)
    {
        // Split by line
        $lines = explode("\n", $content);

        // Trim and convert to lowercase
        $lines = array_map('trim', $lines);
        $lines = array_map('strtolower', $lines);

        // Remove empty lines and comments
        $lines = array_filter($lines, function ($line) {
            return (0 === strlen($line) || '#' === $line[0]) ? false : $line;
        });

        return $lines;
    }
168867
public static function buildQueryStr($params) {
        $arrTmp = array();
        foreach ($params as $k => $v){
            //参数为空不参与签名
            if(isset($v) && $v != ''){
                array_push($arrTmp, "$k=$v");
            }
        }
        return implode('&', $arrTmp);
    }
140109
public static function fromContents(string $contents): string
    {
        $class = "";
        $namespace = "";
        $tokens = token_get_all($contents);
        $len = count($tokens);

        for ($i = 0; $i < $len; $i++) {
            if ($tokens[$i][0] === T_NAMESPACE) {
                for ($j = $i + 1; $j < $len; $j++) {
                    if ($tokens[$j][0] === T_STRING) {
                        $namespace .= "\\".$tokens[$j][1];
                    }
                    else if ($tokens[$j] === "{" || $tokens[$j] === ";") {
                        break;
                    }
                }
            }
            else if ($tokens[$i][0] === T_CLASS) {
                for ($j = $i+1; $j < $len; $j++) {
                    if ($tokens[$j][0] === T_STRING) {
                        $class = $tokens[$j][1];
                        break 2;
                    }
                }
            }
        }

        if ($class === "") {
            return "";
        }
        return ($namespace === "")
            ? $class
            : trim($namespace."\\".$class, "\\");
    }
1218882
private function lex(string $contents): array
    {
        $contents = $this->removeSuperfluousStartingWhitespace($contents);

        // performance optimalization; if there is no inline tag, don't bother splitting it up.
        if (strpos($contents, '{@') === false) {
            return [$contents];
        }

        return preg_split(
            '/\{
                # "{@}" is not a valid inline tag. This ensures that we do not treat it as one, but treat it literally.
                (?!@\})
                # We want to capture the whole tag line, but without the inline tag delimiters.
                (\@
                    # Match everything up to the next delimiter.
                    [^{}]*
                    # Nested inline tag content should not be captured, or it will appear in the result separately.
                    (?:
                        # Match nested inline tags.
                        (?:
                            # Because we did not catch the tag delimiters earlier, we must be explicit with them here.
                            # Notice that this also matches "{}", as a way to later introduce it as an escape sequence.
                            \{(?1)?\}
                            |
                            # Make sure we match hanging "{".
                            \{
                        )
                        # Match content after the nested inline tag.
                        [^{}]*
                    )* # If there are more inline tags, match them as well. We use "*" since there may not be any
                       # nested inline tags.
                )
            \}/Sux',
            $contents,
            0,
            PREG_SPLIT_DELIM_CAPTURE
        );
    }
1213631
public function sign($contents, $privateKey)
    {
        $rsa = new RSA();
        $rsa->loadKey($privateKey);

        $rsa->setSignatureMode(RSA::SIGNATURE_PKCS1);

        return $rsa->sign($contents);
    }
562168
public function getFilename($content)
    {
        $doc = $this->reader->parseToDocument($content);
        $this->reader->loadXpathFromDoc($doc);

        $nameType = $doc->documentElement->localName;
        $ruc = $this->getRuc($nameType);
        $document = $this->reader->getValue('cbc:ID');

        $type = $this->getTypeFromDoc($nameType);
        if (empty($type)) {
            return $ruc.self::CONCAT_CHR.$document;
        }

        return implode(self::CONCAT_CHR, [$ruc, $type, $document]);
    }
820346
public function getDescendantsContentUids($contents)
    {
        if (false === is_array($contents)) {
            $contents = array($contents);
        }

        $meta = $this->_em->getClassMetadata('BackBee\ClassContent\Indexes\IdxContentContent');

        $q = $this->_em->getConnection()
                ->createQueryBuilder()
                ->select('c.'.$meta->getColumnName('subcontent_uid'))
                ->from($meta->getTableName(), 'c');

        $index = 0;
        $atleastone = false;
        foreach ($contents as $content) {
            if (false === ($content instanceof AbstractClassContent)) {
                continue;
            }

            if (true === $content->isElementContent()) {
                continue;
            }

            $q->orWhere('c.'.$meta->getColumnName('content_uid').' = :uid'.$index)
                    ->setParameter('uid'.$index, $content->getUid());

            $index++;
            $atleastone = true;
        }

        return (true === $atleastone) ? array_unique($q->execute()->fetchAll(\PDO::FETCH_COLUMN)) : array();
    }
921173
public function runMinificationRules($contents)
    {
        do {
            $originalContents = $contents;
            $contents = preg_replace(array_keys($this->minifyRules), array_values($this->minifyRules), $contents);
        } while ($originalContents != $contents);

        return $contents;
    }
484629
private function getRandomBlockFilter($contents)
    {
        return rand(0, 1) ? $contents[array_rand($contents)]->path . '*' : $contents[array_rand($contents)]->path;
    }