FileOffsetEncryption.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.IO;
  3. using UnityEngine;
  4. namespace YooAsset
  5. {
  6. // 文件偏移加密方式的示例代码
  7. public class FileOffsetEncryption : IEncryptionServices
  8. {
  9. public EncryptResult Encrypt(EncryptFileInfo fileInfo)
  10. {
  11. if (fileInfo.BundleName.Contains("dressup")
  12. || fileInfo.BundleName.Contains("dll")
  13. || fileInfo.BundleName.Contains("card"))
  14. {
  15. Debug.Log($"Encrypt {fileInfo.BundleName}");
  16. int offset = 30;
  17. byte[] fileData = File.ReadAllBytes(fileInfo.FilePath);
  18. var encryptedData = new byte[fileData.Length + offset];
  19. Buffer.BlockCopy(fileData, 0, encryptedData, offset, fileData.Length);
  20. EncryptResult result = new EncryptResult();
  21. result.LoadMethod = EBundleLoadMethod.LoadFromFileOffset;
  22. result.EncryptedData = encryptedData;
  23. return result;
  24. }
  25. else
  26. {
  27. EncryptResult result = new EncryptResult();
  28. result.LoadMethod = EBundleLoadMethod.Normal;
  29. return result;
  30. }
  31. }
  32. }
  33. }