/* using System.Collections.Generic; using System.IO; using System.Security.Cryptography; using System.Text; using UnityEngine; public class DataManager { private static string path = Application.persistentDataPath + "/save.dat"; // ⚠️ Example only (don’t hardcode in real production) private static readonly byte[] key = Encoding.UTF8.GetBytes("1234567890123456"); private static readonly byte[] iv = Encoding.UTF8.GetBytes("6543210987654321"); public static DataManager Instance; // ---------------- SAVE ---------------- public void Save(LeaderboardData data) { string json = JsonUtility.ToJson(data); string hash = ComputeHash(json); SaveWrapper wrapper = new SaveWrapper { json = json, hash = hash }; string wrapperJson = JsonUtility.ToJson(wrapper); string encrypted = Encrypt(wrapperJson); File.WriteAllText(path, encrypted); Debug.Log("Secure save written"); } // ---------------- LOAD ---------------- public LeaderboardData Load() { if (!File.Exists(path)) return new LeaderboardData(); string encrypted = File.ReadAllText(path); string decrypted = Decrypt(encrypted); SaveWrapper wrapper = JsonUtility.FromJson(decrypted); string expectedHash = ComputeHash(wrapper.json); if (expectedHash != wrapper.hash) { Debug.LogWarning("Save file tampered!"); return new LeaderboardData(); } return JsonUtility.FromJson(wrapper.json); } public List GetLeaderboardScores() { return Load().leaderboardScores; } // ---------------- HASH ---------------- private string ComputeHash(string input) { using (SHA256 sha = SHA256.Create()) { byte[] bytes = sha.ComputeHash(Encoding.UTF8.GetBytes(input)); return System.Convert.ToBase64String(bytes); } } // ---------------- AES ENCRYPT ---------------- private string Encrypt(string plainText) { using (Aes aes = Aes.Create()) { aes.Key = key; aes.IV = iv; ICryptoTransform encryptor = aes.CreateEncryptor(); byte[] inputBytes = Encoding.UTF8.GetBytes(plainText); byte[] encrypted = encryptor.TransformFinalBlock(inputBytes, 0, inputBytes.Length); return System.Convert.ToBase64String(encrypted); } } // ---------------- AES DECRYPT ---------------- private string Decrypt(string cipherText) { using (Aes aes = Aes.Create()) { aes.Key = key; aes.IV = iv; ICryptoTransform decryptor = aes.CreateDecryptor(); byte[] inputBytes = System.Convert.FromBase64String(cipherText); byte[] decrypted = decryptor.TransformFinalBlock(inputBytes, 0, decrypted.Length); return Encoding.UTF8.GetString(decrypted); } } } // ================= DATA CLASSES (same file) ================= [System.Serializable] public class LeaderboardData { public List leaderboardScores = new List(); } [System.Serializable] public class SaveWrapper { public string json; public string hash; }*/