Skip to content

Commit f391219

Browse files
committed
Merge branch 'v3'
2 parents 4a6fd48 + 8d8b11e commit f391219

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

SPHDecode/Implementations/Cryptography.cs

+18-8
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,26 @@ namespace SPHDecode.Implementations
88
{
99
public static class Cryptography
1010
{
11-
private static byte[] KEY = new byte[] { 22, 39, 41, 141, 146, 199, 249, 4, 22, 135, 33, 125, 42, 121, 133, 198, 243, 104, 188, 35, 46, 48, 11, 1, 142, 200, 248, 130, 113, 81, 73, 62 }; // "1627298D92C7F9041687217D2A7985C6F368BC232E300B018EC8F8827151493E"
12-
private static byte[] IV = new byte[] { 89, 48, 127, 77, 236, 78, 199, 214, 97, 87, 151, 33, 145, 150, 117, 0 }; // "59307F4DEC4EC7D66157972191967500"
11+
private static byte[] V2KEY = new byte[] { 22, 39, 41, 141, 146, 199, 249, 4, 22, 135, 33, 125, 42, 121, 133, 198, 243, 104, 188, 35, 46, 48, 11, 1, 142, 200, 248, 130, 113, 81, 73, 62 }; // "1627298D92C7F9041687217D2A7985C6F368BC232E300B018EC8F8827151493E"
12+
private static byte[] V2IV = new byte[] { 89, 48, 127, 77, 236, 78, 199, 214, 97, 87, 151, 33, 145, 150, 117, 0 }; // "59307F4DEC4EC7D66157972191967500"
1313

14-
public static byte[] Decrypt(byte[] clearText)
14+
private static byte[] V3KEY = new byte[] { 221, 31, 187, 117, 150, 208, 213, 139, 191, 51, 106, 186, 57, 19, 102, 237, 62, 215, 70, 8, 73, 187, 158, 250, 185, 100, 156, 153, 152, 99, 191, 37 }; // "DD1FBB7596D0D58BBF336ABA391366ED3ED7460849BB9EFAB9649C999863BF25"
15+
private static byte[] V3IV = new byte[] { 179, 128, 225, 122, 12, 71, 110, 138, 72, 11, 85, 37, 58, 186, 230, 102 }; // "B380E17A0C476E8A480B55253ABAE666"
16+
17+
public static byte[] Decrypt(byte[] clearText)
1518
{
1619
byte[] response;
1720

1821
try
1922
{
20-
byte[] data = AESHelper(clearText, true);
23+
byte[] data;
24+
try {
25+
data = AESHelper(V3KEY, V3IV, clearText, true);
26+
}
27+
catch (Exception)
28+
{
29+
data = AESHelper(V2KEY, V2IV, clearText, true);
30+
}
2131

2232
response = Zlib.DecompressData(data);
2333
}
@@ -53,7 +63,7 @@ public static byte[] Encrypt(byte[] data)
5363
{
5464
byte[] comp = Zlib.CompressData(clearText);
5565

56-
response = AESHelper(comp);
66+
response = AESHelper(V2KEY, V2IV, comp);
5767
}
5868
catch (Exception ex)
5969
{
@@ -65,7 +75,7 @@ public static byte[] Encrypt(byte[] data)
6575
return response;
6676
}
6777

68-
private static byte[] AESHelper (byte[] data, bool decrypt = false)
78+
private static byte[] AESHelper (byte[] key, byte[] iv, byte[] data, bool decrypt = false)
6979
{
7080
Aes encryptor = Aes.Create();
7181

@@ -78,8 +88,8 @@ private static byte[] AESHelper (byte[] data, bool decrypt = false)
7888
encryptor.BlockSize = 128;
7989
encryptor.Mode = CipherMode.CBC;
8090
encryptor.Padding = PaddingMode.Zeros;
81-
encryptor.Key = KEY;
82-
encryptor.IV = IV;
91+
encryptor.Key = key;
92+
encryptor.IV = iv;
8393

8494
MemoryStream ms = new MemoryStream();
8595
CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write);

SPHDecode/Model/MainWindowModel.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ private void OndecryptExecute()
8686
byte[] orig = File.ReadAllBytes(srcFile);
8787
byte[] decode = util.removeNullByte(Cryptography.Decrypt(orig));
8888

89-
if (Object.Equals(decode, null).Equals(false))
90-
{
91-
File.WriteAllBytes(dstFile, decode);
92-
MessageBox.Show("config decrypted successfully", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information);
93-
}
94-
}
89+
if (Object.Equals(decode, null).Equals(false))
90+
{
91+
File.WriteAllBytes(dstFile, decode);
92+
MessageBox.Show("config decrypted successfully", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information);
93+
}
94+
}
9595

9696
public MainWindowModel()
9797
{

0 commit comments

Comments
 (0)