From 343b2ba28b29d2c43e74abc85b86dcd742f876ff Mon Sep 17 00:00:00 2001 From: Rutherther Date: Sat, 11 Feb 2023 18:20:33 +0100 Subject: [PATCH] fix(crypto): decrypt with correct encoding in world cryptography --- .../ClientWorldCryptography.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Core/NosSmooth.Cryptography/ClientWorldCryptography.cs b/Core/NosSmooth.Cryptography/ClientWorldCryptography.cs index f12eeb0..a6f4daf 100644 --- a/Core/NosSmooth.Cryptography/ClientWorldCryptography.cs +++ b/Core/NosSmooth.Cryptography/ClientWorldCryptography.cs @@ -33,7 +33,7 @@ public class ClientWorldCryptography : ICryptography public string Decrypt(in ReadOnlySpan bytes, Encoding encoding) { int index = 0; - var currentPacket = new StringBuilder(); + var currentPacket = new List(); while (index < bytes.Length) { @@ -41,7 +41,7 @@ public class ClientWorldCryptography : ICryptography if (currentByte == 0xFF) { - currentPacket.Append('\n'); + currentPacket.Add((byte)'\n'); continue; } @@ -64,7 +64,7 @@ public class ClientWorldCryptography : ICryptography if (first != 0x6E) { - currentPacket.Append(first); + currentPacket.Add((byte)first); } if (length <= 1) @@ -82,7 +82,7 @@ public class ClientWorldCryptography : ICryptography if (second != 0x6E) { - currentPacket.Append(second); + currentPacket.Add((byte)second); } length -= 2; @@ -99,12 +99,12 @@ public class ClientWorldCryptography : ICryptography { if (index < bytes.Length) { - currentPacket.Append((char)(bytes[index] ^ 0xFF)); + currentPacket.Add((byte)(bytes[index] ^ 0xFF)); index++; } else if (index == bytes.Length) { - currentPacket.Append((char)0xFF); + currentPacket.Add((byte)'\n'); index++; } @@ -113,7 +113,8 @@ public class ClientWorldCryptography : ICryptography } } - return currentPacket.ToString(); + byte[] tmp = Encoding.Convert(encoding, Encoding.UTF8, currentPacket.ToArray()); + return Encoding.UTF8.GetString(tmp); } /// -- 2.48.1