Ejemplo n.º 1
0
    public static string EncodeWithGzip(string m, string key)
    {
        byte[] raw = Encoding.UTF8.GetBytes(m);
        byte[] dest;
        using (MemoryStream stream = new MemoryStream())
        {
            using (GZipOutputStream stream1 = new GZipOutputStream(stream))
            {
                stream1.IsStreamOwner = false;
                stream1.Write(raw, 0, raw.Length);
                stream1.Flush();
                stream1.Finish();
                dest = stream.ToArray();
            }
        }

        byte[] bytes = new byte[dest.Length + 0x1a];
        Array.Copy(dest, 0, bytes, 0x1a, dest.Length);
        Array.Copy(Encoding.UTF8.GetBytes("0000000000"), 0, bytes, 0, 10);
        //1
        //还有26byte待解决
        int lengthOfACode = 0;

        key = AuthCode.MD5(key);
        string str  = AuthCode.MD5(key.Substring(0x10, 0x10));
        string s    = AuthCode.MD5(key.Substring(0x0, 0x10));
        string str3 = (lengthOfACode > 0) ? m.Substring(0, lengthOfACode) : "";
        string pass = str + AuthCode.MD5(str + str3);

        //1
        byte[] buffer4 = new byte[(bytes.Length - 0x1a) + s.Length];
        Array.Copy(dest, 0, buffer4, 0, dest.Length);
        Array.Copy(Encoding.UTF8.GetBytes(s), 0, buffer4, dest.Length, s.Length);
        Array.Copy(Encoding.UTF8.GetBytes(AuthCode.MD5(buffer4)), 0, bytes, 10, 0x10);

        byte[] buffer = RC4(bytes, pass);

        string result = Convert.ToBase64String(buffer);

        return("#" + new string(new char[lengthOfACode]) + result);
    }