Esempio n. 1
0
        public bool Handshake01(string UserName, string Password)
        {
            var aes = Aes.Create(); aes.GenerateKey(); aes.GenerateIV();

            layer = new AESLayer(aes.Key, aes.IV, s);
            var rsa = RSA.Create();

            rsa.ImportRSAPublicKey(RSAPubKey, out _);
            {
                //Send AES Key
                //byte[] Part1 = new byte[190];
                //for (int i = 0; i < 32; i++)
                //{
                //    Part1[i] = aes.Key[i];
                //}
                var FData0 = rsa.Encrypt(aes.Key, RSAEncryptionPadding.OaepSHA256);
                s.Send(FData0, 256, SocketFlags.None);
            }
            //{
            //    //Send AES Key
            //    byte[] Part2 = new byte[66];
            //    for (int i = 0; i < 66; i++)
            //    {
            //        Part2[i] = aes.Key[i + 190];
            //    }
            //    var FData1 = rsa.Encrypt(Part2, RSAEncryptionPadding.OaepSHA256);
            //    s.Send(FData1, 256, SocketFlags.None);
            //}
            {
                //Send AES IV
                var FinalEncIV = rsa.Encrypt(aes.IV, RSAEncryptionPadding.OaepSHA256);
                s.Send(FinalEncIV, 256, SocketFlags.None);
            }
            {
                //Send U/N
                layer.Write(Encoding.UTF8.GetBytes(UserName));
                layer.Write(Encoding.UTF8.GetBytes(Password));
            }
            {
                byte[] receieved = null;
                layer.Read(out receieved);
                if (receieved.Length >= 2)
                {
                    if (receieved.Length is 2 && receieved[0] == 'N' && receieved[1] == 'O')
                    {
                        return(false);
                    }
                    else
                    {
                        Auth = Encoding.UTF8.GetString(receieved);
                        Task.Run(Listen);
                        return(true);
                    }
                }
Esempio n. 2
0
 internal static void AddSocket(AESLayer s)
 {
     layers.Add(s);
 }