Skip to content

Commit 88917da

Browse files
committed
modified manifest services interface (v3.4.4)
1 parent bcb710b commit 88917da

8 files changed

Lines changed: 306 additions & 419 deletions

File tree

Assets/OxGFrame/AssetLoader/Scripts/Editor/Bundle/YooAssets/EncryptionServices.cs

Lines changed: 176 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace OxGFrame.AssetLoader.Editor
66
{
7-
public class OffsetEncryption : IEncryptionServices
7+
public class OffsetEncryption : IEncryptionServices, IManifestProcessServices
88
{
99
private int? _dummySize = null;
1010

@@ -15,6 +15,7 @@ public OffsetEncryption(int dummySize)
1515
this._dummySize = dummySize;
1616
}
1717

18+
#region IEncryptionServices
1819
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
1920
{
2021
var cryptogramSettings = CryptogramSettingSetup.GetCryptogramSetting();
@@ -41,9 +42,28 @@ public EncryptResult Encrypt(EncryptFileInfo fileInfo)
4142
return result;
4243
}
4344
}
45+
#endregion
46+
47+
#region IManifestProcessServices
48+
public byte[] ProcessManifest(byte[] fileData)
49+
{
50+
var cryptogramSettings = CryptogramSettingSetup.GetCryptogramSetting();
51+
52+
int dummySize = this._dummySize == null ? cryptogramSettings.dummySize : (int)this._dummySize;
53+
54+
if (FileCryptogram.Offset.EncryptBytes(ref fileData, dummySize))
55+
{
56+
Debug.Log($"Manifest Offset Cryptogram => dummySize: {dummySize}");
57+
58+
return fileData;
59+
}
60+
61+
return null;
62+
}
63+
#endregion
4464
}
4565

46-
public class XorEncryption : IEncryptionServices
66+
public class XorEncryption : IEncryptionServices, IManifestProcessServices
4767
{
4868
private byte? _xorKey = null;
4969

@@ -54,6 +74,7 @@ public XorEncryption(byte xorKey)
5474
this._xorKey = xorKey;
5575
}
5676

77+
#region IEncryptionServices
5778
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
5879
{
5980
var cryptogramSettings = CryptogramSettingSetup.GetCryptogramSetting();
@@ -80,9 +101,28 @@ public EncryptResult Encrypt(EncryptFileInfo fileInfo)
80101
return result;
81102
}
82103
}
104+
#endregion
105+
106+
#region IManifestProcessServices
107+
public byte[] ProcessManifest(byte[] fileData)
108+
{
109+
var cryptogramSettings = CryptogramSettingSetup.GetCryptogramSetting();
110+
111+
byte xorKey = this._xorKey == null ? cryptogramSettings.xorKey : (byte)this._xorKey;
112+
113+
if (FileCryptogram.XOR.EncryptBytes(fileData, xorKey))
114+
{
115+
Debug.Log($"Manifest XorCryptogram => xorKey: {xorKey}");
116+
117+
return fileData;
118+
}
119+
120+
return null;
121+
}
122+
#endregion
83123
}
84124

85-
public class HT2XorEncryption : IEncryptionServices
125+
public class HT2XorEncryption : IEncryptionServices, IManifestProcessServices
86126
{
87127
private byte? _hXorKey = null;
88128
private byte? _tXorKey = null;
@@ -97,6 +137,7 @@ public HT2XorEncryption(byte hXorKey, byte tXorKey, byte jXorKey)
97137
this._jXorKey = jXorKey;
98138
}
99139

140+
#region IEncryptionServices
100141
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
101142
{
102143
var cryptogramSettings = CryptogramSettingSetup.GetCryptogramSetting();
@@ -125,9 +166,30 @@ public EncryptResult Encrypt(EncryptFileInfo fileInfo)
125166
return result;
126167
}
127168
}
169+
#endregion
170+
171+
#region IManifestProcessServices
172+
public byte[] ProcessManifest(byte[] fileData)
173+
{
174+
var cryptogramSettings = CryptogramSettingSetup.GetCryptogramSetting();
175+
176+
byte hXorKey = this._hXorKey == null ? cryptogramSettings.hXorKey : (byte)this._hXorKey;
177+
byte tXorKey = this._tXorKey == null ? cryptogramSettings.tXorKey : (byte)this._tXorKey;
178+
byte jXorKey = this._jXorKey == null ? cryptogramSettings.jXorKey : (byte)this._jXorKey;
179+
180+
if (FileCryptogram.HT2XOR.EncryptBytes(fileData, hXorKey, tXorKey, jXorKey))
181+
{
182+
Debug.Log($"Manifest HT2Xor Cryptogram => hXorKey: {hXorKey}, tXorKey: {tXorKey}, jXorKey: {jXorKey}");
183+
184+
return fileData;
185+
}
186+
187+
return null;
188+
}
189+
#endregion
128190
}
129191

130-
public class HT2XorPlusEncryption : IEncryptionServices
192+
public class HT2XorPlusEncryption : IEncryptionServices, IManifestProcessServices
131193
{
132194
private byte? _hXorKey = null;
133195
private byte? _tXorKey = null;
@@ -144,6 +206,7 @@ public HT2XorPlusEncryption(byte hXorKey, byte tXorKey, byte j1XorKey, byte j2Xo
144206
this._j2XorKey = j2XorKey;
145207
}
146208

209+
#region IEncryptionServices
147210
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
148211
{
149212
var cryptogramSettings = CryptogramSettingSetup.GetCryptogramSetting();
@@ -173,9 +236,31 @@ public EncryptResult Encrypt(EncryptFileInfo fileInfo)
173236
return result;
174237
}
175238
}
239+
#endregion
240+
241+
#region IManifestProcessServices
242+
public byte[] ProcessManifest(byte[] fileData)
243+
{
244+
var cryptogramSettings = CryptogramSettingSetup.GetCryptogramSetting();
245+
246+
byte hXorKey = this._hXorKey == null ? cryptogramSettings.hXorPlusKey : (byte)this._hXorKey;
247+
byte tXorKey = this._tXorKey == null ? cryptogramSettings.tXorPlusKey : (byte)this._tXorKey;
248+
byte j1XorKey = this._j1XorKey == null ? cryptogramSettings.j1XorPlusKey : (byte)this._j1XorKey;
249+
byte j2XorKey = this._j2XorKey == null ? cryptogramSettings.j2XorPlusKey : (byte)this._j2XorKey;
250+
251+
if (FileCryptogram.HT2XORPlus.EncryptBytes(fileData, hXorKey, tXorKey, j1XorKey, j2XorKey))
252+
{
253+
Debug.Log($"Manifest HT2XorPlus Cryptogram => hXorKey: {hXorKey}, tXorKey: {tXorKey}, j1XorKey: {j1XorKey}, j2XorKey: {j2XorKey}");
254+
255+
return fileData;
256+
}
257+
258+
return null;
259+
}
260+
#endregion
176261
}
177262

178-
public class AesEncryption : IEncryptionServices
263+
public class AesEncryption : IEncryptionServices, IManifestProcessServices
179264
{
180265
private string _aesKey = null;
181266
private string _aesIv = null;
@@ -188,6 +273,7 @@ public AesEncryption(string aesKey, string aesIv)
188273
this._aesIv = aesIv;
189274
}
190275

276+
#region IEncryptionServices
191277
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
192278
{
193279
var cryptogramSettings = CryptogramSettingSetup.GetCryptogramSetting();
@@ -215,9 +301,29 @@ public EncryptResult Encrypt(EncryptFileInfo fileInfo)
215301
return result;
216302
}
217303
}
304+
#endregion
305+
306+
#region IManifestProcessServices
307+
public byte[] ProcessManifest(byte[] fileData)
308+
{
309+
var cryptogramSettings = CryptogramSettingSetup.GetCryptogramSetting();
310+
311+
string key = string.IsNullOrEmpty(this._aesKey) ? cryptogramSettings.aesKey : this._aesKey;
312+
string iv = string.IsNullOrEmpty(this._aesIv) ? cryptogramSettings.aesIv : this._aesIv;
313+
314+
if (FileCryptogram.AES.EncryptBytes(ref fileData, key, iv))
315+
{
316+
Debug.Log($"Manifest AES Cryptogram => key: {key}, iv: {iv}");
317+
318+
return fileData;
319+
}
320+
321+
return null;
322+
}
323+
#endregion
218324
}
219325

220-
public class ChaCha20Encryption : IEncryptionServices
326+
public class ChaCha20Encryption : IEncryptionServices, IManifestProcessServices
221327
{
222328
private string _chacha20Key = null;
223329
private string _chacha20Nonce = null;
@@ -232,6 +338,7 @@ public ChaCha20Encryption(string chacha20Key, string chacha20Nonce, uint chacha2
232338
this._chacha20Counter = chacha20Counter;
233339
}
234340

341+
#region IEncryptionServices
235342
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
236343
{
237344
var cryptogramSettings = CryptogramSettingSetup.GetCryptogramSetting();
@@ -260,9 +367,29 @@ public EncryptResult Encrypt(EncryptFileInfo fileInfo)
260367
return result;
261368
}
262369
}
370+
#endregion
371+
372+
#region IManifestProcessServices
373+
public byte[] ProcessManifest(byte[] fileData)
374+
{
375+
var cryptogramSettings = CryptogramSettingSetup.GetCryptogramSetting();
376+
377+
string key = string.IsNullOrEmpty(this._chacha20Key) ? cryptogramSettings.chacha20Key : this._chacha20Key;
378+
string nonce = string.IsNullOrEmpty(this._chacha20Nonce) ? cryptogramSettings.chacha20Nonce : this._chacha20Nonce;
379+
uint counter = this._chacha20Counter == null ? (uint)cryptogramSettings.chacha20Counter : (uint)this._chacha20Counter;
380+
381+
if (FileCryptogram.ChaCha20.EncryptBytes(ref fileData, key, nonce, counter))
382+
{
383+
Debug.Log($"Manifest ChaCha20 Cryptogram => key: {key}, nonce: {nonce}, counter: {counter}");
384+
385+
return fileData;
386+
}
387+
return null;
388+
}
389+
#endregion
263390
}
264391

265-
public class XXTEAEncryption : IEncryptionServices
392+
public class XXTEAEncryption : IEncryptionServices, IManifestProcessServices
266393
{
267394
private string _xxteaKey = null;
268395

@@ -273,6 +400,7 @@ public XXTEAEncryption(string xxteaKey)
273400
this._xxteaKey = xxteaKey;
274401
}
275402

403+
#region IEncryptionServices
276404
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
277405
{
278406
var cryptogramSettings = CryptogramSettingSetup.GetCryptogramSetting();
@@ -299,9 +427,28 @@ public EncryptResult Encrypt(EncryptFileInfo fileInfo)
299427
return result;
300428
}
301429
}
430+
#endregion
431+
432+
#region IManifestProcessServices
433+
public byte[] ProcessManifest(byte[] fileData)
434+
{
435+
var cryptogramSettings = CryptogramSettingSetup.GetCryptogramSetting();
436+
437+
string key = string.IsNullOrEmpty(this._xxteaKey) ? cryptogramSettings.xxteaKey : this._xxteaKey;
438+
439+
if (FileCryptogram.XXTEA.EncryptBytes(ref fileData, key))
440+
{
441+
Debug.Log($"Manifest XXTEA Cryptogram => key: {key}");
442+
443+
return fileData;
444+
}
445+
446+
return null;
447+
}
448+
#endregion
302449
}
303450

304-
public class OffsetXorEncryption : IEncryptionServices
451+
public class OffsetXorEncryption : IEncryptionServices, IManifestProcessServices
305452
{
306453
private byte? _offsetXorKey = null;
307454
private int? _offsetXorDummySize = null;
@@ -314,6 +461,7 @@ public OffsetXorEncryption(byte offsetXorKey, int offsetXorDummySize)
314461
this._offsetXorDummySize = offsetXorDummySize;
315462
}
316463

464+
#region IEncryptionServices
317465
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
318466
{
319467
var cryptogramSettings = CryptogramSettingSetup.GetCryptogramSetting();
@@ -341,5 +489,25 @@ public EncryptResult Encrypt(EncryptFileInfo fileInfo)
341489
return result;
342490
}
343491
}
492+
#endregion
493+
494+
#region IManifestProcessServices
495+
public byte[] ProcessManifest(byte[] fileData)
496+
{
497+
var cryptogramSettings = CryptogramSettingSetup.GetCryptogramSetting();
498+
499+
byte key = this._offsetXorKey == null ? (byte)cryptogramSettings.offsetXorKey : (byte)this._offsetXorKey;
500+
int dummySize = this._offsetXorDummySize == null ? (int)cryptogramSettings.offsetXorDummySize : (int)this._offsetXorDummySize;
501+
502+
if (FileCryptogram.OffsetXOR.EncryptBytes(fileData, key, dummySize))
503+
{
504+
Debug.Log($"Manifest OffsetXOR Cryptogram => key: {key}, dummySize: {dummySize}");
505+
506+
return fileData;
507+
}
508+
509+
return null;
510+
}
511+
#endregion
344512
}
345513
}

0 commit comments

Comments
 (0)