天天看點

unity+AssetBundle位元組數組加密

1.加密:對assetbundle的位元組數組每位進行與key的異或處理(相同為0,不同為1)

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);
            }
        }
    }
}      
stream = File.ReadAllBytes(uri);
            Encypt(ref stream);
            bundle = AssetBundle.LoadFromMemory(stream);