Bladeren bron

1不能随便用不认识的包

hexiaojie 4 dagen geleden
bovenliggende
commit
8ed88a8788

+ 3 - 1
GameClient/Assets/Game/HotUpdate/AccountData/AccountManager.cs

@@ -12,7 +12,9 @@ namespace GFGGame
         private List<AccountData> _cachedAccounts = new List<AccountData>();
 
         // 单例实例
-        private static readonly Lazy<AccountManager> _instance = new Lazy<AccountManager>(() => new AccountManager());
+        private static readonly SimpleLazy<AccountManager> _instance =
+            new SimpleLazy<AccountManager>(() => new AccountManager());
+
         public static AccountManager Instance => _instance.Value;
 
         // 私有构造函数,防止外部实例化

+ 2 - 52
GameClient/Assets/Game/HotUpdate/AccountData/AesEncryption.cs

@@ -7,64 +7,14 @@ namespace GFGGame
 {
     public static class AesEncryption
     {
-        // !!!重要警告!!!
-        // 硬编码在客户端的密钥并不安全,容易被反编译获取。
-        // 这只能防止简单的窥探,无法抵御专业黑客。
-        // 对于极度敏感的信息,请考虑其他方案(如服务端令牌验证)。
-        private static readonly string Key = "45418100000000000000000000000000"; // 必须恰好是32字节
-        private static readonly string IV = "1234567890123456"; // 必须恰好是16字节
-
         public static string Encrypt(string plainText)
         {
-            using (Aes aesAlg = Aes.Create())
-            {
-                aesAlg.Key = Encoding.UTF8.GetBytes(Key);
-                aesAlg.IV = Encoding.UTF8.GetBytes(IV);
-
-                ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
-                using (MemoryStream msEncrypt = new MemoryStream())
-                {
-                    using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
-                    {
-                        using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
-                        {
-                            swEncrypt.Write(plainText);
-                        }
-                    }
-
-                    return Convert.ToBase64String(msEncrypt.ToArray());
-                }
-            }
+            return plainText;
         }
 
         public static string Decrypt(string cipherText)
         {
-            try
-            {
-                byte[] buffer = Convert.FromBase64String(cipherText);
-                using (Aes aesAlg = Aes.Create())
-                {
-                    aesAlg.Key = Encoding.UTF8.GetBytes(Key);
-                    aesAlg.IV = Encoding.UTF8.GetBytes(IV);
-
-                    ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
-                    using (MemoryStream msDecrypt = new MemoryStream(buffer))
-                    {
-                        using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
-                        {
-                            using (StreamReader srDecrypt = new StreamReader(csDecrypt))
-                            {
-                                return srDecrypt.ReadToEnd();
-                            }
-                        }
-                    }
-                }
-            }
-            catch
-            {
-                // 解密失败(可能数据被篡改或密钥错误)
-                return null;
-            }
+            return cipherText;
         }
     }
 }

+ 41 - 0
GameClient/Assets/Game/HotUpdate/AccountData/SimpleLazy.cs

@@ -0,0 +1,41 @@
+using System;
+
+namespace GFGGame
+{
+    // 替代 System.Lazy<T> 的简单实现
+    // 替代 System.Lazy<T> 的简易实现
+    public class SimpleLazy<T>
+    {
+        private readonly Func<T> _initializer;
+        private T _value;
+        private bool _isInitialized;
+        private readonly object _lock = new object();
+
+        public SimpleLazy(Func<T> initializer)
+        {
+            _initializer = initializer ?? throw new ArgumentNullException(nameof(initializer));
+        }
+
+        public T Value
+        {
+            get
+            {
+                if (!_isInitialized)
+                {
+                    lock (_lock)
+                    {
+                        if (!_isInitialized)
+                        {
+                            _value = _initializer();
+                            _isInitialized = true;
+                        }
+                    }
+                }
+
+                return _value;
+            }
+        }
+
+        public bool IsValueCreated => _isInitialized;
+    }
+}

+ 3 - 0
GameClient/Assets/Game/HotUpdate/AccountData/SimpleLazy.cs.meta

@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 40e26eb0a8bc478ab48e59a32f853dff
+timeCreated: 1761164883