【AB加密】加密工具代码提交
parent
b6c01c82cf
commit
6a817f1b01
|
|
@ -0,0 +1,95 @@
|
|||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using LuaInterface;
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
|
||||
namespace GameLogic {
|
||||
public static class MEncyptUtil {
|
||||
//
|
||||
//加密/解密
|
||||
static byte[] crypt(byte[] data, string key)
|
||||
{
|
||||
int[] ri = new int[data.Length];
|
||||
byte[] cl = System.Text.Encoding.Default.GetBytes(key);
|
||||
for(long i = 0; i<data.Length; i++)
|
||||
{
|
||||
ri[i] = data[i] ^ cl[i % cl.Length];
|
||||
}
|
||||
byte[] rb = new byte[ri.Length * sizeof(int)];
|
||||
Buffer.BlockCopy(ri, 0, rb, 0, rb.Length);
|
||||
|
||||
|
||||
byte[] r = new byte[ri.Length];
|
||||
int x = 0;
|
||||
for (int i = 0; i < rb.Length; i++)
|
||||
{
|
||||
if(i%4 == 0)
|
||||
{
|
||||
r[x++] = rb[i];
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 加载AB包
|
||||
public static byte[] DecyptAB(byte[] data, string key, ulong offset)
|
||||
{
|
||||
byte[] rb ;
|
||||
|
||||
if (key == null || key == "")
|
||||
{
|
||||
rb = crypt(data, key);
|
||||
}
|
||||
else {
|
||||
rb = crypt(data, key);
|
||||
}
|
||||
byte[] r = new byte[rb.Length - (int)offset];
|
||||
for (int i = (int)offset; i < rb.Length; i++)
|
||||
{
|
||||
r[i - (int)offset] = rb[i];
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
[MenuItem("Build/TEST")]
|
||||
static void load()
|
||||
{
|
||||
byte[] a = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
|
||||
string s = "";
|
||||
for(int i = 0;i < a.Length; i++)
|
||||
{
|
||||
s += a[i];
|
||||
}
|
||||
XDebug.Log.l("a = " + s);
|
||||
|
||||
|
||||
|
||||
byte[] b = crypt(a, "key");
|
||||
s = "";
|
||||
for (int i = 0; i < b.Length; i++)
|
||||
{
|
||||
s += b[i];
|
||||
}
|
||||
XDebug.Log.l("b = " + s);
|
||||
|
||||
|
||||
|
||||
byte[] c = crypt(b, "key");
|
||||
s = "";
|
||||
for (int i = 0; i < c.Length; i++)
|
||||
{
|
||||
s += c[i];
|
||||
}
|
||||
XDebug.Log.l("c = " + s);
|
||||
|
||||
|
||||
//File.ReadAllBytes("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ad73e333e7b929e43a333d72c073e873
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in New Issue