예제 #1
0
        /// <summary>
        /// Generates the packet.
        /// </summary>
        /// <param name="ServerIV1">The serverIV1</param>
        /// <param name="ServerIV2">The serverIV2</param>
        /// <param name="P">The P.</param>
        /// <param name="G">The G.</param>
        /// <param name="ServerPublicKey">The server public key.</param>
        /// <returns></returns>
        private byte[] GeneratePacket(byte[] ServerIV1, byte[] ServerIV2, string P, string G, string ServerPublicKey)
        {
            int    PAD_LEN   = 11;
            int    _junk_len = 12;
            string tqs       = "TQServer";

            using (var ms = new MemoryStream())
            {
                byte[] pad = new byte[PAD_LEN];
                CryptographicRandom.NextBytes(pad);
                byte[] junk = new byte[_junk_len];
                CryptographicRandom.NextBytes(junk);
                int size = 47 + P.Length + G.Length + ServerPublicKey.Length + 12 + 8 + 8;
                using (var bw = new BinaryWriter(ms))
                {
                    bw.Write(pad);
                    bw.Write(size - PAD_LEN);
                    bw.Write((UInt32)_junk_len);
                    bw.Write(junk);
                    bw.Write((UInt32)ServerIV2.Length);
                    bw.Write(ServerIV2);
                    bw.Write((UInt32)ServerIV1.Length);
                    bw.Write(ServerIV1);
                    bw.Write((UInt32)P.Length);
                    foreach (var fP in P)
                    {
                        bw.BaseStream.WriteByte((byte)fP);
                    }
                    bw.Write((UInt32)G.ToCharArray().Length);
                    foreach (var fG in G)
                    {
                        bw.BaseStream.WriteByte((byte)fG);
                    }
                    bw.Write((UInt32)ServerPublicKey.ToCharArray().Length);
                    foreach (var SPK in ServerPublicKey)
                    {
                        bw.BaseStream.WriteByte((byte)SPK);
                    }
                    foreach (var tq in tqs)
                    {
                        bw.BaseStream.WriteByte((byte)tq);
                    }
                    byte[] Packet = new byte[ms.Length];
                    Packet = ms.ToArray();
                    return(Packet);
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Fills the buffer with random bytes.
 /// </summary>
 /// <param name="buffer">The buffer.</param>
 public static void NextBytes(byte[] buffer)
 {
     CryptographicRandom.NextBytes(buffer);
 }