Example #1
0
        private void ParseMinaQueueThread()
        {
            try
            {
                while (true)
                {
                    byte[] body = _minaQueue.Dequeue();

                    if (body != null)
                    {
                        _parser.Do(RC4.Convert(body, 4));
                    }

                    Thread.Sleep(10);
                }
            }
            catch (SocketException ex)
            {
                Shutdown();
                Notified?.Invoke(CVResult.ReceiveCallbackFailed, ex);
            }
            catch (ObjectDisposedException)
            {
                _connected = false;
                Notified?.Invoke(CVResult.InfocenterNotConnected, this);
            }
            catch (Exception ex)
            {
                Notified?.Invoke(CVResult.ExceptionHappened, ex);
            }
        }
Example #2
0
    private string Encrypt(string JSON, string seed)
    {
        m_output += "Encrypting data: " + JSON + '\n';
        string        hash         = MD5Hash.GetHash(seed);    //Getting the hash of the randomized string
        RC4           packetKey    = new RC4(m_encryptionKey); //Setting the key for the RC4
        StringBuilder combinedHash = new StringBuilder();

        combinedHash.Append(hash);
        combinedHash.Append(packetKey.Convert(JSON));                 //Gets the proper RC4 string then Combine the MD5 and the RC4.
        return(BaseN.ProduceString(combinedHash.ToString()));
    }
Example #3
0
        /// <summary>
        /// 将类型和protobuff打包成流
        /// 4B+2B+protobuffer.Length
        /// protobuffer.Length+2 cmd protobuffer
        /// </summary>
        /// <param name="type"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        public static byte[] Packaging <T>(int type, T t)
        {
            byte[] src = ProtobufWrapper.ByteSerialize <T>(t);

            byte[] buff = new byte[4 + 2 + src.Length];

            byte[] headerbuf = BitConverter.GetBytes(src.Length + 2);

            byte[] header = new byte[4] {
                headerbuf[3], headerbuf[2], headerbuf[1], headerbuf[0]
            };
            byte[] cmdbuff = BitConverter.GetBytes(type);
            byte[] cmd     = new byte[2] {
                cmdbuff[1], cmdbuff[0]
            };

            //header
            Buffer.BlockCopy(header, 0, buff, 0, header.Length);
            //cmd
            Buffer.BlockCopy(cmd, 0, buff, header.Length, cmd.Length);
            //protocolbuffer
            Buffer.BlockCopy(src, 0, buff, header.Length + cmd.Length, src.Length);

            /**
             * wg:update
             */
            //以下两个行为Java客户端的请求加密方式
            // byte[] ciphertext = RC4.RC4Custom(plaintext, key.getComplexKey(), key.getOutputCounter());
            //key.outputCounterIncrease(ciphertext.length);
            //一下为获取增量
            CustomRC4Key key = CustomRC4Key.CreateCustomRC4Key();

            byte[] rc4byte = RC4.Convert(buff, 0);// key.GetOutputCounter());
            key.OutputCounterIncrease(rc4byte.Length);
            //end
            return(rc4byte);
        }