From a9a9368b9b59476cb24f4a32108640c9d5a61b00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Wed, 12 Feb 2025 16:27:51 +0800 Subject: [PATCH] update test sample --- .../Test Sample/Runtime/TestEncryption.cs | 120 +++++++++--------- 1 file changed, 62 insertions(+), 58 deletions(-) diff --git a/Assets/YooAsset/Samples~/Test Sample/Runtime/TestEncryption.cs b/Assets/YooAsset/Samples~/Test Sample/Runtime/TestEncryption.cs index 46b1dfef..9f057562 100644 --- a/Assets/YooAsset/Samples~/Test Sample/Runtime/TestEncryption.cs +++ b/Assets/YooAsset/Samples~/Test Sample/Runtime/TestEncryption.cs @@ -4,6 +4,7 @@ using System.Text; using UnityEngine; using YooAsset; +#region 文件流 /// /// 资源文件解密流 /// @@ -29,6 +30,35 @@ public class BundleStream : FileStream } } +/// +/// 文件流加密方式 +/// +public class FileStreamEncryption : IEncryptionServices +{ + public EncryptResult Encrypt(EncryptFileInfo fileInfo) + { + if (fileInfo.BundleName.Contains("_gameres_audio")) + { + var fileData = File.ReadAllBytes(fileInfo.FileLoadPath); + for (int i = 0; i < fileData.Length; i++) + { + fileData[i] ^= BundleStream.KEY; + } + + EncryptResult result = new EncryptResult(); + result.Encrypted = true; + result.EncryptedData = fileData; + return result; + } + else + { + EncryptResult result = new EncryptResult(); + result.Encrypted = false; + return result; + } + } +} + /// /// 资源文件流加载解密类 /// @@ -81,6 +111,37 @@ public class FileStreamDecryption : IDecryptionServices return 1024; } } +#endregion + +#region 文件偏移 +/// +/// 文件偏移加密方式 +/// +public class FileOffsetEncryption : IEncryptionServices +{ + public EncryptResult Encrypt(EncryptFileInfo fileInfo) + { + // 注意:只对音频资源包加密 + if (fileInfo.BundleName.Contains("_gameres_audio")) + { + int offset = 32; + byte[] fileData = File.ReadAllBytes(fileInfo.FileLoadPath); + var encryptedData = new byte[fileData.Length + offset]; + Buffer.BlockCopy(fileData, 0, encryptedData, offset, fileData.Length); + + EncryptResult result = new EncryptResult(); + result.Encrypted = true; + result.EncryptedData = encryptedData; + return result; + } + else + { + EncryptResult result = new EncryptResult(); + result.Encrypted = false; + return result; + } + } +} /// /// 资源文件偏移加载解密类 @@ -132,61 +193,4 @@ public class FileOffsetDecryption : IDecryptionServices return 32; } } - -/// -/// 文件偏移加密方式 -/// -public class FileOffsetEncryption : IEncryptionServices -{ - public EncryptResult Encrypt(EncryptFileInfo fileInfo) - { - // 注意:只对音频资源包加密 - if (fileInfo.BundleName.Contains("_gameres_audio")) - { - int offset = 32; - byte[] fileData = File.ReadAllBytes(fileInfo.FileLoadPath); - var encryptedData = new byte[fileData.Length + offset]; - Buffer.BlockCopy(fileData, 0, encryptedData, offset, fileData.Length); - - EncryptResult result = new EncryptResult(); - result.Encrypted = true; - result.EncryptedData = encryptedData; - return result; - } - else - { - EncryptResult result = new EncryptResult(); - result.Encrypted = false; - return result; - } - } -} - -/// -/// 文件流加密方式 -/// -public class FileStreamEncryption : IEncryptionServices -{ - public EncryptResult Encrypt(EncryptFileInfo fileInfo) - { - if (fileInfo.BundleName.Contains("_gameres_audio")) - { - var fileData = File.ReadAllBytes(fileInfo.FileLoadPath); - for (int i = 0; i < fileData.Length; i++) - { - fileData[i] ^= BundleStream.KEY; - } - - EncryptResult result = new EncryptResult(); - result.Encrypted = true; - result.EncryptedData = fileData; - return result; - } - else - { - EncryptResult result = new EncryptResult(); - result.Encrypted = false; - return result; - } - } -} \ No newline at end of file +#endregion \ No newline at end of file