11using OxGFrame . AssetLoader . Bundle ;
2- using System . IO ;
32using UnityEngine ;
43using YooAsset ;
54
@@ -16,16 +15,29 @@ public static CryptogramSetting GetCryptogramSetting()
1615 }
1716 }
1817
19- public class OffSetEncryption : IEncryptionServices
18+ public class OffsetEncryption : IEncryptionServices
2019 {
20+ private int ? _randomSeed = null ;
21+ private int ? _dummySize = null ;
22+
23+ public OffsetEncryption ( )
24+ {
25+ }
26+
27+ public OffsetEncryption ( int randomSeed , int dummySize )
28+ {
29+ this . _randomSeed = randomSeed ;
30+ this . _dummySize = dummySize ;
31+ }
32+
2133 public EncryptResult Encrypt ( EncryptFileInfo fileInfo )
2234 {
2335 var cryptogramSettings = CryptogramSettingSetup . GetCryptogramSetting ( ) ;
2436
2537 string filePath = fileInfo . FilePath ;
2638
27- int randomSeed = cryptogramSettings . randomSeed ;
28- int dummySize = cryptogramSettings . dummySize ;
39+ int randomSeed = this . _randomSeed == null ? cryptogramSettings . randomSeed : ( int ) this . _randomSeed ;
40+ int dummySize = this . _dummySize == null ? cryptogramSettings . dummySize : ( int ) this . _dummySize ;
2941
3042 byte [ ] fileData = FileCryptogram . Offset . OffsetEncryptBytes ( filePath , randomSeed , dummySize ) ;
3143
@@ -49,13 +61,24 @@ public EncryptResult Encrypt(EncryptFileInfo fileInfo)
4961
5062 public class XorEncryption : IEncryptionServices
5163 {
64+ private byte ? _xorKey = null ;
65+
66+ public XorEncryption ( )
67+ {
68+ }
69+
70+ public XorEncryption ( byte xorKey )
71+ {
72+ this . _xorKey = xorKey ;
73+ }
74+
5275 public EncryptResult Encrypt ( EncryptFileInfo fileInfo )
5376 {
5477 var cryptogramSettings = CryptogramSettingSetup . GetCryptogramSetting ( ) ;
5578
5679 string filePath = fileInfo . FilePath ;
5780
58- byte xorKey = cryptogramSettings . xorKey ;
81+ byte xorKey = this . _xorKey == null ? cryptogramSettings . xorKey : ( byte ) this . _xorKey ;
5982
6083 byte [ ] fileData = FileCryptogram . XOR . XorEncryptBytes ( filePath , xorKey ) ;
6184
@@ -79,15 +102,30 @@ public EncryptResult Encrypt(EncryptFileInfo fileInfo)
79102
80103 public class HT2XorEncryption : IEncryptionServices
81104 {
105+ private byte ? _hXorKey = null ;
106+ private byte ? _tXorKey = null ;
107+ private byte ? _jXorKey = null ;
108+
109+ public HT2XorEncryption ( )
110+ {
111+ }
112+
113+ public HT2XorEncryption ( byte hXorKey , byte tXorKey , byte jXorKey )
114+ {
115+ this . _hXorKey = hXorKey ;
116+ this . _tXorKey = tXorKey ;
117+ this . _jXorKey = jXorKey ;
118+ }
119+
82120 public EncryptResult Encrypt ( EncryptFileInfo fileInfo )
83121 {
84122 var cryptogramSettings = CryptogramSettingSetup . GetCryptogramSetting ( ) ;
85123
86124 string filePath = fileInfo . FilePath ;
87125
88- byte hXorKey = cryptogramSettings . hXorKey ;
89- byte tXorKey = cryptogramSettings . tXorKey ;
90- byte jXorKey = cryptogramSettings . jXorKey ;
126+ byte hXorKey = this . _hXorKey == null ? cryptogramSettings . hXorKey : ( byte ) this . _hXorKey ;
127+ byte tXorKey = this . _tXorKey == null ? cryptogramSettings . tXorKey : ( byte ) this . _tXorKey ;
128+ byte jXorKey = this . _jXorKey == null ? cryptogramSettings . jXorKey : ( byte ) this . _jXorKey ;
91129
92130 byte [ ] fileData = FileCryptogram . HT2XOR . HT2XorEncryptBytes ( filePath , hXorKey , tXorKey , jXorKey ) ;
93131
@@ -111,16 +149,33 @@ public EncryptResult Encrypt(EncryptFileInfo fileInfo)
111149
112150 public class HT2XorPlusEncryption : IEncryptionServices
113151 {
152+ private byte ? _hXorKey = null ;
153+ private byte ? _tXorKey = null ;
154+ private byte ? _j1XorKey = null ;
155+ private byte ? _j2XorKey = null ;
156+
157+ public HT2XorPlusEncryption ( )
158+ {
159+ }
160+
161+ public HT2XorPlusEncryption ( byte hXorKey , byte tXorKey , byte j1XorKey , byte j2XorKey )
162+ {
163+ this . _hXorKey = hXorKey ;
164+ this . _tXorKey = tXorKey ;
165+ this . _j1XorKey = j1XorKey ;
166+ this . _j2XorKey = j2XorKey ;
167+ }
168+
114169 public EncryptResult Encrypt ( EncryptFileInfo fileInfo )
115170 {
116171 var cryptogramSettings = CryptogramSettingSetup . GetCryptogramSetting ( ) ;
117172
118173 string filePath = fileInfo . FilePath ;
119174
120- byte hXorKey = cryptogramSettings . hXorPlusKey ;
121- byte tXorKey = cryptogramSettings . tXorPlusKey ;
122- byte j1XorKey = cryptogramSettings . j1XorPlusKey ;
123- byte j2XorKey = cryptogramSettings . j2XorPlusKey ;
175+ byte hXorKey = this . _hXorKey == null ? cryptogramSettings . hXorPlusKey : ( byte ) this . _hXorKey ;
176+ byte tXorKey = this . _tXorKey == null ? cryptogramSettings . tXorPlusKey : ( byte ) this . _tXorKey ;
177+ byte j1XorKey = this . _j1XorKey == null ? cryptogramSettings . j1XorPlusKey : ( byte ) this . _j1XorKey ;
178+ byte j2XorKey = this . _j2XorKey == null ? cryptogramSettings . j2XorPlusKey : ( byte ) this . _j2XorKey ;
124179
125180 byte [ ] fileData = FileCryptogram . HT2XORPlus . HT2XorPlusEncryptBytes ( filePath , hXorKey , tXorKey , j1XorKey , j2XorKey ) ;
126181
@@ -144,14 +199,27 @@ public EncryptResult Encrypt(EncryptFileInfo fileInfo)
144199
145200 public class AesEncryption : IEncryptionServices
146201 {
202+ private string _aesKey = null ;
203+ private string _aesIv = null ;
204+
205+ public AesEncryption ( )
206+ {
207+ }
208+
209+ public AesEncryption ( string aesKey , string aesIv )
210+ {
211+ this . _aesKey = aesKey ;
212+ this . _aesIv = aesIv ;
213+ }
214+
147215 public EncryptResult Encrypt ( EncryptFileInfo fileInfo )
148216 {
149217 var cryptogramSettings = CryptogramSettingSetup . GetCryptogramSetting ( ) ;
150218
151219 string filePath = fileInfo . FilePath ;
152220
153- string aesKey = cryptogramSettings . aesKey ;
154- string aesIv = cryptogramSettings . aesIv ;
221+ string aesKey = string . IsNullOrEmpty ( this . _aesKey ) ? cryptogramSettings . aesKey : this . _aesKey ;
222+ string aesIv = string . IsNullOrEmpty ( this . _aesIv ) ? cryptogramSettings . aesIv : this . _aesIv ;
155223
156224 byte [ ] fileData = FileCryptogram . AES . AesEncryptBytes ( filePath , aesKey , aesIv ) ;
157225
0 commit comments