예제 #1
0
        public override void ParsePayload(int payloadSize, Stream stream)
        {
            base.ParsePayload(payloadSize, stream);

            Payload = new byte[payloadSize];
            byte[] encryptedIV = Utils.ReadFull(stream, payloadSize);
            cryptor.Write(encryptedIV, 0, encryptedIV.Length);
            cryptor.Decrypt(Payload, 0, Payload.Length);
        }
예제 #2
0
        public override void ParsePayload(int payloadSize, Stream stream)
        {
            base.ParsePayload(payloadSize, stream);
            byte[] buffer = new byte[payloadSize];

            Utils.ReadFull(stream, buffer, payloadSize);
            cryptor.Write(buffer, 0, buffer.Length);
            cryptor.Decrypt(buffer, 0, buffer.Length);
            string str = Encoding.UTF8.GetString(buffer);

            Payload = AuthInfo.FromString(Account.FromString(str), str);
        }
예제 #3
0
        public void DuplexRWTest()
        {
            CryptoMemoryStream memoryStream = new CryptoMemoryStream(1024, plainKey);

            byte[] buffer = new byte[data.Length];

            for (int i = 0; i < 2; i++)
            {
                memoryStream.Encrypt(data, 0, data.Length);
                Console.WriteLine(memoryStream.Read(buffer, 0, buffer.Length));
                Console.WriteLine(string.Join(" ", buffer));

                memoryStream.Write(buffer, 0, buffer.Length);
                memoryStream.Decrypt(buffer, 0, buffer.Length);

                Assert.IsTrue(data.SequenceEqual(buffer));
            }
        }