mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Create Encryption.cs
This commit is contained in:
38
Assets/TEngine/Editor/Resource/Encryption.cs
Normal file
38
Assets/TEngine/Editor/Resource/Encryption.cs
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user