对明文进行加密

@param string $text 需要加密的明文

@param string $appId

@return array
968318
public function encrypt($text, $appId)
    {
        try {
            //获得16位随机字符串，填充到明文之前
            $key    = $this->getAESKey();
            $random = $this->getRandomStr();
            $text   = $this->encode($random . pack('N', strlen($text)) . $text . $appId);

            $iv = substr($key, 0, 16);

            $encrypted = openssl_encrypt($text, 'aes-256-cbc', $key, OPENSSL_RAW_DATA | OPENSSL_NO_PADDING, $iv);

            //print(base64_encode($encrypted));
            //使用BASE64对加密后的字符串进行编码
            return [ErrorCode::$OK, base64_encode($encrypted)];
        } catch (Exception $e) {
            //print $e;
            return [ErrorCode::$EncryptAESError, null];
        }
    }
908764
public function staticPhp($text)
    {
        $textExplode      = explode('->', $text);
        $variableName     = str_replace('$', '', array_shift($textExplode));
        $variableVariable = $this->variables;

        if (isset($variableVariable[$variableName]) === false) {
            throw new \InvalidArgumentException(
                sprintf('variable %s does not exist', $variableName)
            );
        }

        $textExplode = array_map(
            function ($value) {
                return str_replace('()', '', $value);
            },
            $textExplode
        );

        $instance = $variableVariable[$variableName];
        $keys     = array_values($textExplode);
        $lastKey  = array_pop($keys);

        foreach ($textExplode as $key => $method) {
            if ($instance === null && $lastKey !== $key) {
                throw new \InvalidArgumentException(sprintf('method %s return null', $method));
            } elseif (false === method_exists($instance, $method)) {
                throw new \InvalidArgumentException(sprintf('method %s does not exist on %s', $method, $text));
            } else {
                $instance = $instance->$method();
            }
        }

        return $instance;
    }
1198604
protected function _decode($text)
    {
        $restore = mb_internal_encoding();
        mb_internal_encoding($this->_appCharset);
        $return = mb_decode_mimeheader($text);
        mb_internal_encoding($restore);

        return $return;
    }
945169
public final void append(final CharSequence text, final int start, final int end) {
        getView().append(text, start, end);
    }
865182
public function process($text, $args = null)
    {
        $text = $this->processDocuments($text, $args);
        $text = $this->processGalleries($text, $args);

        return $text;
    }
1195390
protected function _addAction(&$text)
    {
        // All: Add the action if left empty
        if (preg_match_all('#<\s*form[^>]+action=""#si', $text, $matches, PREG_SET_ORDER))
        {
            $action = $this->getTemplate()->route();

            foreach ($matches as $match)
            {
                $str = str_replace('action=""', 'action="' . $action . '"', $match[0]);
                $text = str_replace($match[0], $str, $text);
            }
        }

        return $this;
    }
254551
public static function getMenu($appid, $pid = 0) {
		$button = static::find()->where(['appid' => $appid, 'conditional' => 0, 'pid' => $pid])->select('id, type, name, key, url, media_id')->orderby('list_order, created_at')->asArray()->all();

		foreach($button as $index => $_button) {
			$button[$index]['sub_button'] = static::getMenu($appid, $_button['id']);
			unset($_button['id']);
		}

		return $button;
	}
414950
public function decrypt($encrypted, $appid)
    {

		try {
			//使用BASE64对需要解密的字符串进行解码
			$ciphertext_dec = base64_decode($encrypted);
			$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
			$iv = substr($this->key, 0, 16);
			mcrypt_generic_init($module, $this->key, $iv);

			//解密
			$decrypted = mdecrypt_generic($module, $ciphertext_dec);
			mcrypt_generic_deinit($module);
			mcrypt_module_close($module);
		} catch (\Exception $e) {
			@error_log('Decrypt AES Error: ' . $e->getMessage(), 0);
			return FALSE;
		}


		try {
			//去除补位字符
			$pkc_encoder = new Pkcs7Encoder;
			$result = $pkc_encoder->decode($decrypted);
			//去除16位随机字符串,网络字节序和AppId
			if (strlen($result) < 16) {
				return "";
			}
			$content = substr($result, 16, strlen($result));
			$len_list = unpack("N", substr($content, 0, 4));
			$xml_len = $len_list[1];
			$xml_content = substr($content, 4, $xml_len);
			$from_appid = substr($content, $xml_len + 4);
		} catch (\Exception $e) {
			@error_log('Illegal Buffer: ' . $e->getMessage(), 0);
			return FALSE;
		}
		if ($from_appid != $appid) {
			@error_log('Validate Appid Error', 0);
			return FALSE;
		}
		return $xml_content;
	}
548913
public function decrypt($encrypted, $appId)
    {
        try {
            //使用BASE64对需要解密的字符串进行解码
            $ciphertext = base64_decode($encrypted, true);
            $module     = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
            $iv         = substr($this->AESKey, 0, 16);

            mcrypt_generic_init($module, $this->AESKey, $iv);

            //解密
            $decrypted = mdecrypt_generic($module, $ciphertext);
            mcrypt_generic_deinit($module);
            mcrypt_module_close($module);
        } catch (Exception $e) {
            throw new Exception($e->getMessage(), self::ERROR_DECRYPT_AES);
        }

        try {
            //去除补位字符
            $result = $this->decode($decrypted);

            //去除16位随机字符串,网络字节序和AppId
            if (strlen($result) < 16) {
                return '';
            }

            $content   = substr($result, 16, strlen($result));
            $listLen   = unpack('N', substr($content, 0, 4));
            $xmlLen    = $listLen[1];
            $xml       = substr($content, 4, $xmlLen);
            $fromAppId = trim(substr($content, $xmlLen + 4));
        } catch (Exception $e) {
            throw new Exception($e->getMessage(), self::ERROR_INVALID_XML);
        }

        if ($fromAppId !== $appId) {
            throw new Exception('Invalid appId.', self::ERROR_INVALID_APPID);
        }

        return $xml;
    }
8848
private function initPayload($text)
    {
        $payload = new Payload();
        $payload->setOptions($this->getOptions());
        $payload->setQueryText($text);
        return $payload->createPayload();
    }
611287
@Override
    public String encode( String text ) {
        if (text == null) return null;
        StringBuilder sb = new StringBuilder();
        CharacterIterator iter = new StringCharacterIterator(text);
        for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
            switch (c) {
                case '&':
                    sb.append("&amp;");
                    break;
                case '"':
                    sb.append("&quot;");
                    break;
                case '<':
                    sb.append("&lt;");
                    break;
                case '>':
                    sb.append("&gt;");
                    break;
                case '\'':
                    sb.append("&#039;");
                    break;
                default:
                    sb.append(c);
            }
        }
        return sb.toString();
    }
972795
public function sendText($text)
    {
        $cmd = implode(' ', array('SEND', 'TEXT', '"' . $text . '"'));
        $result = $this->send($cmd);
        if ($result->isResult(-1)) {
            throw new PAGIException('Command failed');
        }
    }
236521
public static function getChar(string $text, int $offset): array
    {
        if ($text == '') {
            return [
                'letter' => '',
                'length' => 0,
            ];
        }

        $char   = substr($text, $offset, 1);
        $length = 1;
        if ((ord($char) & 0xE0) == 0xC0) {
            $length = 2;
        }
        if ((ord($char) & 0xF0) == 0xE0) {
            $length = 3;
        }
        if ((ord($char) & 0xF8) == 0xF0) {
            $length = 4;
        }
        $letter = substr($text, $offset, $length);

        return [
            'letter' => $letter,
            'length' => $length,
        ];
    }
526975
public static void append(Path self, Object text) throws IOException {
        append(self, text, Charset.defaultCharset().name(), false);
    }
660948
public static function extractSql(string $text): array
    {
        // remove comments
        // inline
        $text = (string)preg_replace('/\s*(?:--|#).*$/um', '', $text);
        // multi-line
        $text = (string)preg_replace('/\/\*[^*]*(\*)?[^*]*\*\//um', '', $text);
        // flatten and filter
        $text = (string)preg_replace('/\n/', ' ', $text);
        $text = (string)preg_replace('/\s{2,}/', ' ', $text);
        $text = trim($text, '; ');
        return $text === '' ? [] : preg_split('/\s*;\s*/', $text);
    }
452973
@Override
    public TextObject append(CharSequence text) {
        if (maxTextLength>0 && stringBuilder.length()>=maxTextLength) return this;

        text = textFilter.filter(text);

        //unfortunately this code can't be put into a TextFilter because:
        //1) the limit could not be detected early, a lot of work would be done to waste time and memory
        //2) the last character of the existing string builder could not be seen. if it is a space, we don't want
        //   to add yet another space.
        char pre = stringBuilder.length()==0 ? 0 : stringBuilder.charAt(stringBuilder.length()-1);
        for (int i=0; i<text.length() && (maxTextLength==0 || stringBuilder.length()<maxTextLength); i++) {
            char c = CharNormalizer.normalize(text.charAt(i));
            if (c != ' ' || pre != ' ') {
                stringBuilder.append(c);
            }
            pre = c;
        }

        return this;
    }
1186829
public function getById($appId, $scanId, $fileId, array $queryParams = [])
    {
        $response = $this->api
            ->applications()
            ->scans()
            ->files()
            ->getById($appId, $scanId, $fileId, $queryParams);

        return new FileResponse($response);
    }