Unity 异或加密解密资源

加密过程:

新构建出来的AB包→通过指定的密钥对AB包文件进行修改→得到加密的AB

解密过程:

加密的AB包→通过指定的密钥对AB包文件进行还原→得到解密后得AB

同理,其他数据的加密过程也大同小异

 

 

    //异或
    public AssetBundle DecryptAB(string Path) {
        int AssetKey = 666888;    //Key
        byte[] bytes = File.ReadAllBytes(Path);
        bytes = XOREncryption(bytes, AssetKey);
        return AssetBundle.LoadFromMemory(bytes);
    }
    //加密
    public void EncryptionAB(string ABPath)
    {
        int AssetKey = 666888;    //Key
        byte[] ABBytes = File.ReadAllBytes(ABPath);
        ABBytes = XOREncryption(ABBytes, AssetKey);
        File.WriteAllBytes(ABPath, ABBytes);
    }
    //解密
    public byte[] XOREncryption(byte[] bytes, int key)
    {
        for (int i = 0; i < bytes.Length; i++)
        {
            bytes[i] = (byte)(bytes[i] ^ key);
        }
        return bytes;
    }

 

posted @ 2021-08-11 10:30  狐狸爱看书  阅读(347)  评论(0编辑  收藏  举报