mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
* merge commit from milutinke * chat signature & encrypted login * Bug fix :EncryptionResponse format error below 1.18.2 * Implemented chat command signature * Chat message parsing and verification for 1.19 * Add signature settings * Update Simplified Chinese Translation * Clear up comments * Fix wrong variable naming * Bug fix: SignatureV2 Processing
106 lines
2.6 KiB
C#
106 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Security.Cryptography;
|
|
using System.IO;
|
|
|
|
namespace MinecraftClient.Crypto.Streams
|
|
{
|
|
/// <summary>
|
|
/// An encrypted stream using AES, used for encrypting network data on the fly using AES.
|
|
/// This is the regular AesStream class used with the regular .NET framework from Microsoft.
|
|
/// </summary>
|
|
|
|
public class RegularAesStream : Stream, IAesStream
|
|
{
|
|
CryptoStream enc;
|
|
CryptoStream dec;
|
|
public RegularAesStream(Stream stream, byte[] key)
|
|
{
|
|
BaseStream = stream;
|
|
enc = new CryptoStream(stream, GenerateAES(key).CreateEncryptor(), CryptoStreamMode.Write);
|
|
dec = new CryptoStream(stream, GenerateAES(key).CreateDecryptor(), CryptoStreamMode.Read);
|
|
}
|
|
public System.IO.Stream BaseStream { get; set; }
|
|
|
|
public override bool CanRead
|
|
{
|
|
get { return true; }
|
|
}
|
|
|
|
public override bool CanSeek
|
|
{
|
|
get { return false; }
|
|
}
|
|
|
|
public override bool CanWrite
|
|
{
|
|
get { return true; }
|
|
}
|
|
|
|
public override void Flush()
|
|
{
|
|
BaseStream.Flush();
|
|
}
|
|
|
|
public override long Length
|
|
{
|
|
get { throw new NotSupportedException(); }
|
|
}
|
|
|
|
public override long Position
|
|
{
|
|
get
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
set
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|
|
|
|
public override int ReadByte()
|
|
{
|
|
return dec.ReadByte();
|
|
}
|
|
|
|
public override int Read(byte[] buffer, int offset, int count)
|
|
{
|
|
return dec.Read(buffer, offset, count);
|
|
}
|
|
|
|
public override long Seek(long offset, System.IO.SeekOrigin origin)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
public override void SetLength(long value)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
public override void WriteByte(byte b)
|
|
{
|
|
enc.WriteByte(b);
|
|
}
|
|
|
|
public override void Write(byte[] buffer, int offset, int count)
|
|
{
|
|
enc.Write(buffer, offset, count);
|
|
}
|
|
|
|
private static Aes GenerateAES(byte[] key)
|
|
{
|
|
Aes aes = Aes.Create();
|
|
aes.Mode = CipherMode.CFB;
|
|
aes.Padding = PaddingMode.None;
|
|
aes.KeySize = 128;
|
|
aes.FeedbackSize = 8;
|
|
aes.Key = key;
|
|
aes.IV = key;
|
|
return aes;
|
|
}
|
|
}
|
|
}
|