1.加密:对assetbundle的字节数组每位进行与key的异或处理(相同为0,不同为1)
代码语言:javascript复制using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace AbEncypt
{
class Program
{
const Byte key = 157;
static void Main(string[] args)
{
var dir = Directory.GetCurrentDirectory();
foreach (var f in new DirectoryInfo(dir).GetFiles("*.assetbundle", SearchOption.AllDirectories))
{
Byte[] temp = File.ReadAllBytes(f.FullName);
Encypt(ref temp);
File.WriteAllBytes(f.FullName, temp);
}
}
static void Encypt(ref Byte[] targetData)
{
int dataLength = targetData.Length;
for (int i = 0; i < dataLength; i)
{
targetData[i] = (byte)(targetData[i] ^ key);
}
}
}
}
把生成的exe放到assetbundle目录下运行,批量加密assetbundle
2.解密:再次进行一次异或处理,返回原正确的字节数组
代码语言:javascript复制 stream = File.ReadAllBytes(uri);
Encypt(ref stream);
bundle = AssetBundle.LoadFromMemory(stream);