Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Returns a big random number based on a minimum value.
 /// The maximum value is (min * 3)
 /// </summary>
 /// <param name="min">The minimum value.</param>
 /// <returns>The random number.</returns>
 public static long NextBig(int min)
 {
     return(CryptographicRandom.NextBig(min));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Returns a big random number.
 /// </summary>
 /// <returns>The random number.</returns>
 public static long NextBig()
 {
     return(CryptographicRandom.NextBig());
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Returns a random number based on a max value.
 /// </summary>
 /// <param name="maxValue">The maximum value.</param>
 /// <returns>The random number.</returns>
 public static int Next(int maxValue)
 {
     return(CryptographicRandom.Next(maxValue));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Returns a random number.
 /// </summary>
 /// <returns>The random number.</returns>
 public static int Next()
 {
     return(CryptographicRandom.Next());
 }