背景
我们发现市面上有其他游戏使用公司的游戏资源,现有的游戏资源并未加密处理。为了提高破解的门槛,想对资源进行加密处理。
异或加密方式可行性分析
- 为什么使用异或加密
采取异或加密的原因在于加解密方式简单,解密性能开销较低,另外也不会改变文件大小。 - 异或加密带来的AssetBundle加载api调用修改
使用加密的AssetBundle需要先把文件读取到byte数组,再对byte数组进行异或解密处理,最后再调用
原来项目使用AssetBundle.LoadFromMemory/AssetBundle.LoadFromMemoryAsync api进行加载。 - LoadFromFile/LoadFromFileAsync与LoadFromMemory/LoadFromMemoryAsync进行对比
3.1 官方信息
AssetBundle.LoadFromFile(Async)
AssetBundle.LoadFromFile is a highly-efficient API intended for loading uncompressed or LZ4-compressed AssetBundle from local storage, such as a hard disk or an SD card.
On desktop standalone, console, and mobile platforms, the API will only load the AssetBundle’s header, and will leave the remaining data on disk. The AssetBundle’s Objects will be loaded on-demand as loading methods (e.g. AssetBundle.Load) are called or as their InstanceIDs are dereferenced. No excess memory will be consumed in this scenario. In the Unity Editor, the API will load the entire AssetBundle into memory, as if the bytes were read off disk and AssetBundle.LoadFromMemoryAsync was used. This API can cause memory spikes to appear during AssetBundle loading if the project is profiled in the Unity Editor. This should not affect performance on-device and these spikes should be re-tested on-device before taking remedial action.
Note: On Android devices with