Files
YooAssetScene/Assets/YooAsset/Samples~/Test Sample/Runtime/CryptoSample/TestProcessManifest.cs
T
何冠峰 db159428c6 update test sample
增加cache file system单元测试
2025-07-17 21:26:13 +08:00

55 lines
1.6 KiB
C#

using System;
using System.IO;
using System.Text;
using System.Collections;
using UnityEngine;
using NUnit.Framework;
using YooAsset;
public class TestProcessManifest : IManifestServices
{
public byte[] ProcessManifest(byte[] fileData)
{
return XorProcess(fileData, "YOO");
}
public byte[] RestoreManifest(byte[] fileData)
{
return XorProcess(fileData, "YOO");
}
/// <summary>
/// 使用异或加密/解密字节数组
/// </summary>
/// <param name="data">输入数据</param>
/// <param name="key">加密密钥</param>
/// <returns>处理后的字节数组</returns>
public static byte[] XorProcess(byte[] data, byte[] key)
{
if (data == null)
throw new ArgumentNullException(nameof(data));
if (key == null || key.Length == 0)
throw new ArgumentException("Key cannot be null or empty");
byte[] result = new byte[data.Length];
for (int i = 0; i < data.Length; i++)
{
// 循环使用密钥中的字节
result[i] = (byte)(data[i] ^ key[i % key.Length]);
}
return result;
}
/// <summary>
/// 使用字符串密钥进行异或处理(自动转换编码)
/// </summary>
/// <param name="data">输入数据</param>
/// <param name="key">字符串密钥</param>
/// <returns>处理后的字节数组</returns>
public static byte[] XorProcess(byte[] data, string key)
{
byte[] keyBytes = System.Text.Encoding.UTF8.GetBytes(key);
return XorProcess(data, keyBytes);
}
}