From b0e33b3c3ac3b0015841efdda0be1598da265cd7 Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Mon, 3 Apr 2023 14:42:51 +0800 Subject: [PATCH] Create Encryption.cs --- Assets/TEngine/Editor/Resource/Encryption.cs | 38 ++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Assets/TEngine/Editor/Resource/Encryption.cs diff --git a/Assets/TEngine/Editor/Resource/Encryption.cs b/Assets/TEngine/Editor/Resource/Encryption.cs new file mode 100644 index 00000000..4eae2e9c --- /dev/null +++ b/Assets/TEngine/Editor/Resource/Encryption.cs @@ -0,0 +1,38 @@ +using System; +using System.IO; +using TEngine; +using YooAsset; + +public class FileOffsetEncryption : IEncryptionServices +{ + public EncryptResult Encrypt(EncryptFileInfo fileInfo) + { + int offset = 32; + byte[] fileData = File.ReadAllBytes(fileInfo.FilePath); + var encryptedData = new byte[fileData.Length + offset]; + Buffer.BlockCopy(fileData, 0, encryptedData, offset, fileData.Length); + + EncryptResult result = new EncryptResult(); + result.LoadMethod = EBundleLoadMethod.LoadFromFileOffset; + result.EncryptedData = encryptedData; + return result; + } +} + +public class FileStreamEncryption : IEncryptionServices +{ + public EncryptResult Encrypt(EncryptFileInfo fileInfo) + { + // LoadFromStream + var fileData = File.ReadAllBytes(fileInfo.FilePath); + for (int i = 0; i < fileData.Length; i++) + { + fileData[i] ^= BundleStream.KEY; + } + + EncryptResult result = new EncryptResult(); + result.LoadMethod = EBundleLoadMethod.LoadFromStream; + result.EncryptedData = fileData; + return result; + } +} \ No newline at end of file