I don't know why, I make the same thing that I make on my PacketLogger, but with a new system (Blowfish/DH) and it's not working. When I check, the IVs are good, the P/G/A/B keys are the good, but I can't decrypt the first client packet... I know how work the blowfish system and the DH exchange. Any idea?
PHP Code:
private void ServerReceiveHandler(Client Client, Byte[] Data)
{
Client.CBlowfish.Decrypt(Data);
try
{
if (!Client.ExchangeCompleted)
{
DiffieHellman.ServerPacket(Data, ref Client.Exchange);
Client.CBlowfish.DiffieHellman = new DH(BigNumber.FromHexString(Client.Exchange.P), BigNumber.FromHexString(Client.Exchange.G));
Client.SBlowfish.DiffieHellman = new DH(BigNumber.FromHexString(Client.Exchange.P), BigNumber.FromHexString(Client.Exchange.G));
Client.CBlowfish.DiffieHellman.GenerateKeys();
Client.SBlowfish.DiffieHellman.GenerateKeys();
DiffieHellman.EditKeyA(ref Data, Client.SBlowfish.DiffieHellman.PublicKey.ToHexString());
DiffieHellman.ServerPacket(Data, ref Client.Exchange);
Client.SendToClient(Data);
}
}
catch (Exception Exc) { Program.WriteLine(Exc); }
}
private void ClientReceiveHandler(Client Client, Byte[] Data)
{
Client.SBlowfish.Decrypt(Data);
try
{
if (!Client.ExchangeCompleted)
{
DiffieHellman.EditKeyB(ref Data, Client.CBlowfish.DiffieHellman.PublicKey.ToHexString());
DiffieHellman.ClientPacket(Data, ref Client.Exchange);
Client.SendToServer(Data);
Client.CBlowfish.SetKey(Client.CBlowfish.DiffieHellman.ComputeKey(BigNumber.FromHexString(Client.Exchange.A)));
Client.SBlowfish.SetKey(Client.SBlowfish.DiffieHellman.ComputeKey(BigNumber.FromHexString(Client.Exchange.B)));
Client.CBlowfish.EncryptIVs = Client.Exchange.ClientIVs;
Client.CBlowfish.DecryptIVs = Client.Exchange.ServerIVs;
Client.SBlowfish.EncryptIVs = Client.Exchange.ServerIVs;
Client.SBlowfish.DecryptIVs = Client.Exchange.ClientIVs;
Client.ExchangeCompleted = true;
}
}
catch (Exception Exc) { Program.WriteLine(Exc); }
}