增加配置文件加密功能
This commit is contained in:
parent
e55224352e
commit
2aa1180d01
@ -15,7 +15,7 @@ MonoBehaviour:
|
||||
m_DefaultGroup: a2c3e28415aafd8428af88db5c968beb
|
||||
m_currentHash:
|
||||
serializedVersion: 2
|
||||
Hash: c8a723bc0c63c665d17c41149c248a03
|
||||
Hash: abb22aa190d6e6ff0f9e90c3848e07cc
|
||||
m_OptimizeCatalogSize: 0
|
||||
m_BuildRemoteCatalog: 0
|
||||
m_BundleLocalCatalog: 0
|
||||
@ -46,9 +46,6 @@ MonoBehaviour:
|
||||
m_GroupAssets:
|
||||
- {fileID: 11400000, guid: aac28c528fd593e499c7335a74997dfc, type: 2}
|
||||
- {fileID: 11400000, guid: 4173f7fadab254447a26f8646c339d71, type: 2}
|
||||
- {fileID: 11400000, guid: 28e031ad0719cc447b756b7fbda966fa, type: 2}
|
||||
- {fileID: 11400000, guid: 080b0bb1663f5254491e970586d73848, type: 2}
|
||||
- {fileID: 11400000, guid: 49e9c076cbc00b541bfff389c69de991, type: 2}
|
||||
- {fileID: 11400000, guid: 33b203fe2c2ea764a8c08f2ac109a7dd, type: 2}
|
||||
- {fileID: 11400000, guid: c480fbd7c042fb34189c0f80d6697421, type: 2}
|
||||
- {fileID: 11400000, guid: edaadc37a9553f446ab9d24da4d2e58d, type: 2}
|
||||
@ -66,8 +63,6 @@ MonoBehaviour:
|
||||
- {fileID: 11400000, guid: 58064667c23853648aa78e1c96706c02, type: 2}
|
||||
- {fileID: 11400000, guid: 3c52ddb8c589ac541b0a52ac6dffb2c1, type: 2}
|
||||
- {fileID: 11400000, guid: 5aa73379b14a6534ebf65a7892ac2ca3, type: 2}
|
||||
- {fileID: 11400000, guid: 69e4a13de0baab5448d844bd6bdc3bb4, type: 2}
|
||||
- {fileID: 11400000, guid: 6cca02b544b1b1b41b2a4188f6b90ed2, type: 2}
|
||||
- {fileID: 11400000, guid: bdcac9e08e486af4794706a07824ef2e, type: 2}
|
||||
- {fileID: 11400000, guid: 5d35af4ee2772ad4da8c163c34c5b4fc, type: 2}
|
||||
- {fileID: 11400000, guid: 66fd1f31a22501d4b937cc2495def34c, type: 2}
|
||||
|
||||
Binary file not shown.
@ -2,6 +2,8 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
@ -113,15 +115,21 @@ public class RoTool : EditorWindow
|
||||
{
|
||||
// 获取文件的名称(不带路径)
|
||||
string fileName = Path.GetFileName(filePath);
|
||||
byte[] fileBytes = File.ReadAllBytes(filePath);
|
||||
byte[] aseFileBytes = CommonUtil.Encrypt(fileBytes);
|
||||
|
||||
// 将文件添加到ZIP档案
|
||||
ZipArchiveEntry entry = zipArchive.CreateEntry(fileName);
|
||||
|
||||
using (Stream entryStream = entry.Open())
|
||||
using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
|
||||
{
|
||||
fileStream.CopyTo(entryStream);
|
||||
entryStream.Write(aseFileBytes, 0, aseFileBytes.Length);
|
||||
}
|
||||
|
||||
// using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
|
||||
// {
|
||||
// fileStream.CopyTo(entryStream);
|
||||
// }
|
||||
|
||||
Debug.Log($"Added file: {fileName} to the ZIP archive.");
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ end
|
||||
|
||||
--接收服务器发送过来的消息...
|
||||
function NetManager:ReceiveMessage(msgBody_, msgId_)
|
||||
LogError("!!!!!!!!!!!!!!!!!Receive msgId : " .. msgId_ );
|
||||
--LogError("!!!!!!!!!!!!!!!!!Receive msgId : " .. msgId_ );
|
||||
--是否关闭屏蔽框..
|
||||
--CloseNetSendMaskWnd(msgId_);
|
||||
local data = ManagerContainer.PbManager:DecodePb(msgId_, msgBody_)
|
||||
|
||||
@ -250,7 +250,7 @@ public class ConfigMgr : Singleton<ConfigMgr>
|
||||
{
|
||||
byte[] fileBytes = new byte[entry.Length];
|
||||
entryStream.Read(fileBytes, 0, fileBytes.Length);
|
||||
string text = Encoding.UTF8.GetString(UnicodeUtil.ConvertToNonBOM(fileBytes));
|
||||
string text = Encoding.UTF8.GetString(UnicodeUtil.ConvertToNonBOM(CommonUtil.Decrypt(fileBytes)));
|
||||
mXmlConfigDict.Add(Path.GetFileNameWithoutExtension(fileName), text);
|
||||
}
|
||||
}
|
||||
@ -277,7 +277,7 @@ public class ConfigMgr : Singleton<ConfigMgr>
|
||||
{
|
||||
byte[] fileBytes = new byte[entry.Length];
|
||||
entryStream.Read(fileBytes, 0, fileBytes.Length);
|
||||
string text = Encoding.UTF8.GetString(UnicodeUtil.ConvertToNonBOM(fileBytes));
|
||||
string text = Encoding.UTF8.GetString(UnicodeUtil.ConvertToNonBOM(CommonUtil.Decrypt(fileBytes)));
|
||||
curname = Path.GetFileNameWithoutExtension(fileName);
|
||||
if (curname.Contains(keyword) && !curname.Equals(keywordname) || text.Length <= 0)
|
||||
continue;
|
||||
|
||||
@ -101,7 +101,7 @@ public class LuaMgr : SingletonMono<LuaMgr>
|
||||
{
|
||||
LuaDic.Remove(fileName);
|
||||
}
|
||||
LuaDic.Add(fileName, fileBytes);
|
||||
LuaDic.Add(fileName, CommonUtil.Decrypt(fileBytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -135,7 +135,7 @@ public class LuaMgr : SingletonMono<LuaMgr>
|
||||
luaPbDic.Remove(fileName);
|
||||
}
|
||||
|
||||
luaPbDic.Add(fileName, fileBytes);
|
||||
luaPbDic.Add(fileName, CommonUtil.Decrypt(fileBytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
public static class CommonUtil
|
||||
{
|
||||
@ -304,4 +307,42 @@ public static class CommonUtil
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private static string ___XXXX_AAAA() => "ADFGBSXCODFGBSXC";
|
||||
private static string ___YYYY_VVVV() => "1D3VBSGCJHFEAVL5";
|
||||
// AES 加密方法
|
||||
public static byte[] Encrypt(byte[] data)
|
||||
{
|
||||
using (Aes aesAlg = Aes.Create())
|
||||
{
|
||||
aesAlg.Key = Encoding.UTF8.GetBytes(___XXXX_AAAA());
|
||||
aesAlg.IV = Encoding.UTF8.GetBytes(___YYYY_VVVV());
|
||||
|
||||
using (MemoryStream msEncrypt = new MemoryStream())
|
||||
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV), CryptoStreamMode.Write))
|
||||
{
|
||||
csEncrypt.Write(data, 0, data.Length);
|
||||
csEncrypt.FlushFinalBlock();
|
||||
return msEncrypt.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AES 解密方法
|
||||
public static byte[] Decrypt(byte[] encryptedData)
|
||||
{
|
||||
using (Aes aesAlg = Aes.Create())
|
||||
{
|
||||
aesAlg.Key = Encoding.UTF8.GetBytes(___XXXX_AAAA());
|
||||
aesAlg.IV = Encoding.UTF8.GetBytes(___YYYY_VVVV());
|
||||
|
||||
using (MemoryStream msDecrypt = new MemoryStream())
|
||||
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV), CryptoStreamMode.Write))
|
||||
{
|
||||
csDecrypt.Write(encryptedData, 0, encryptedData.Length);
|
||||
csDecrypt.FlushFinalBlock();
|
||||
return msDecrypt.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user