Cml\Encry::cry PHP Method

cry() private static method

位加密或解密
private static cry ( string $string, integer $type, string $key ) : mixed
$string string 加密或解密内容
$type integer 类型:1加密 2解密
$key string
return mixed
    private static function cry($string, $type, $key)
    {
        self::createKey($key);
        $type == 2 && ($string = str_replace(['___a', '___b', '___c'], ['/', '+', '='], $string));
        $string = $type == 2 ? base64_decode($string) : substr(md5(self::$auth_key . $string), 0, 8) . $string;
        $str_len = strlen($string);
        $data = [];
        $auth_key_length = strlen(self::$auth_key);
        for ($i = 0; $i <= 256; $i++) {
            $data[$i] = ord(self::$auth_key[$i % $auth_key_length]);
        }
        for ($i = $j = 1; $i < 256; $i++) {
            $j = $data[($i + $data[$i]) % 256];
            $tmp = $data[$i];
            $data[$i] = ord($data[$j]);
            $data[$j] = $tmp;
        }
        $s = '';
        for ($i = $j = 0; $i < $str_len; $i++) {
            $tmp = ($i + $i % 256) % 256;
            $j = $data[$tmp] % 256;
            $n = ($tmp + $j) % 256;
            $code = $data[($data[$j] + $data[$n]) % 256];
            $s .= chr(ord($string[$i]) ^ $code);
        }
        if ($type == 1) {
            return str_replace(['/', '+', '='], ['___a', '___b', '___c'], base64_encode($s));
        } else {
            if (substr(md5(self::$auth_key . substr($s, 8)), 0, 8) == substr($s, 0, 8)) {
                return substr($s, 8);
            }
            return '';
        }
    }