From 07b54cae41eb90f85aec422bc27c42d0bd7c066b Mon Sep 17 00:00:00 2001 From: Stricted Date: Thu, 16 Feb 2017 01:12:00 +0100 Subject: [PATCH 1/2] add v3 config keys --- SPHDecode/Implementations/Cryptography.cs | 36 +++++++++++++++++------ SPHDecode/Model/MainWindowModel.cs | 12 ++++---- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/SPHDecode/Implementations/Cryptography.cs b/SPHDecode/Implementations/Cryptography.cs index d557371..64251e8 100644 --- a/SPHDecode/Implementations/Cryptography.cs +++ b/SPHDecode/Implementations/Cryptography.cs @@ -8,16 +8,27 @@ namespace SPHDecode.Implementations { public static class Cryptography { - 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" - private static byte[] IV = new byte[] { 89, 48, 127, 77, 236, 78, 199, 214, 97, 87, 151, 33, 145, 150, 117, 0 }; // "59307F4DEC4EC7D66157972191967500" + 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" + private static byte[] V2IV = new byte[] { 89, 48, 127, 77, 236, 78, 199, 214, 97, 87, 151, 33, 145, 150, 117, 0 }; // "59307F4DEC4EC7D66157972191967500" - public static byte[] Decrypt(byte[] clearText) + private static byte[] V3KEY = new byte[] { 68, 68, 49, 70, 66, 66, 55, 53, 57, 54, 68, 48, 68, 53, 56, 66, 66, 70, 51, 51, 54, 65, 66, 65, 51, 57, 49, 51, 54, 54, 69, 68, 51, 69, 68, 55, 52, 54, 48, 56, 52, 57, 66, 66, 57, 69, 70, 65, 66, 57, 54, 52, 57, 67, 57, 57, 57, 56, 54, 51, 66, 70, 50, 53, }; // "DD1FBB7596D0D58BBF336ABA391366ED3ED7460849BB9EFAB9649C999863BF25" + private static byte[] V3IV = new byte[] { 66, 51, 56, 48, 69, 49, 55, 65, 48, 67, 52, 55, 54, 69, 56, 65, 52, 56, 48, 66, 53, 53, 50, 53, 51, 65, 66, 65, 69, 54, 54, 54, }; // "B380E17A0C476E8A480B55253ABAE666" + + public static byte[] Decrypt(byte[] clearText, bool v3 = false) { byte[] response; try { - byte[] data = AESHelper(clearText, true); + byte[] data; + if (v3) + { + data = AESHelper(V3KEY, V3IV, clearText, true); + } + else + { + data = AESHelper(V2KEY, V2IV, clearText, true); + } response = Zlib.DecompressData(data); } @@ -37,7 +48,7 @@ public static byte[] Decrypt(byte[] clearText) return response; } - public static byte[] Encrypt(byte[] data) + public static byte[] Encrypt(byte[] data, bool v3 = false) { byte[] response = null; @@ -53,7 +64,14 @@ public static byte[] Encrypt(byte[] data) { byte[] comp = Zlib.CompressData(clearText); - response = AESHelper(comp); + if (v3) + { + response = AESHelper(V3KEY, V3IV, comp); + } + else + { + response = AESHelper(V2KEY, V2IV, comp); + } } catch (Exception ex) { @@ -65,7 +83,7 @@ public static byte[] Encrypt(byte[] data) return response; } - private static byte[] AESHelper (byte[] data, bool decrypt = false) + private static byte[] AESHelper (byte[] key, byte[] iv, byte[] data, bool decrypt = false) { Aes encryptor = Aes.Create(); @@ -78,8 +96,8 @@ private static byte[] AESHelper (byte[] data, bool decrypt = false) encryptor.BlockSize = 128; encryptor.Mode = CipherMode.CBC; encryptor.Padding = PaddingMode.Zeros; - encryptor.Key = KEY; - encryptor.IV = IV; + encryptor.Key = key; + encryptor.IV = iv; MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write); diff --git a/SPHDecode/Model/MainWindowModel.cs b/SPHDecode/Model/MainWindowModel.cs index b7bfa8e..7dcf8b2 100644 --- a/SPHDecode/Model/MainWindowModel.cs +++ b/SPHDecode/Model/MainWindowModel.cs @@ -86,12 +86,12 @@ private void OndecryptExecute() byte[] orig = File.ReadAllBytes(srcFile); byte[] decode = util.removeNullByte(Cryptography.Decrypt(orig)); - if (Object.Equals(decode, null).Equals(false)) - { - File.WriteAllBytes(dstFile, decode); - MessageBox.Show("config decrypted successfully", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); - } - } + if (Object.Equals(decode, null).Equals(false)) + { + File.WriteAllBytes(dstFile, decode); + MessageBox.Show("config decrypted successfully", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); + } + } public MainWindowModel() { From 8d8b11e10a2a017100b0a1fd0f407c27459678f0 Mon Sep 17 00:00:00 2001 From: Stricted Date: Thu, 16 Feb 2017 01:27:20 +0100 Subject: [PATCH 2/2] add the right v3 keys and add v3 config detection on decrypt --- SPHDecode/Implementations/Cryptography.cs | 22 +++++++--------------- SPHDecode/Model/MainWindowModel.cs | 2 +- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/SPHDecode/Implementations/Cryptography.cs b/SPHDecode/Implementations/Cryptography.cs index 64251e8..135a469 100644 --- a/SPHDecode/Implementations/Cryptography.cs +++ b/SPHDecode/Implementations/Cryptography.cs @@ -11,21 +11,20 @@ public static class Cryptography 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" private static byte[] V2IV = new byte[] { 89, 48, 127, 77, 236, 78, 199, 214, 97, 87, 151, 33, 145, 150, 117, 0 }; // "59307F4DEC4EC7D66157972191967500" - private static byte[] V3KEY = new byte[] { 68, 68, 49, 70, 66, 66, 55, 53, 57, 54, 68, 48, 68, 53, 56, 66, 66, 70, 51, 51, 54, 65, 66, 65, 51, 57, 49, 51, 54, 54, 69, 68, 51, 69, 68, 55, 52, 54, 48, 56, 52, 57, 66, 66, 57, 69, 70, 65, 66, 57, 54, 52, 57, 67, 57, 57, 57, 56, 54, 51, 66, 70, 50, 53, }; // "DD1FBB7596D0D58BBF336ABA391366ED3ED7460849BB9EFAB9649C999863BF25" - private static byte[] V3IV = new byte[] { 66, 51, 56, 48, 69, 49, 55, 65, 48, 67, 52, 55, 54, 69, 56, 65, 52, 56, 48, 66, 53, 53, 50, 53, 51, 65, 66, 65, 69, 54, 54, 54, }; // "B380E17A0C476E8A480B55253ABAE666" + 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" + private static byte[] V3IV = new byte[] { 179, 128, 225, 122, 12, 71, 110, 138, 72, 11, 85, 37, 58, 186, 230, 102 }; // "B380E17A0C476E8A480B55253ABAE666" - public static byte[] Decrypt(byte[] clearText, bool v3 = false) + public static byte[] Decrypt(byte[] clearText) { byte[] response; try { byte[] data; - if (v3) - { + try { data = AESHelper(V3KEY, V3IV, clearText, true); } - else + catch (Exception) { data = AESHelper(V2KEY, V2IV, clearText, true); } @@ -48,7 +47,7 @@ public static byte[] Decrypt(byte[] clearText, bool v3 = false) return response; } - public static byte[] Encrypt(byte[] data, bool v3 = false) + public static byte[] Encrypt(byte[] data) { byte[] response = null; @@ -64,14 +63,7 @@ public static byte[] Encrypt(byte[] data, bool v3 = false) { byte[] comp = Zlib.CompressData(clearText); - if (v3) - { - response = AESHelper(V3KEY, V3IV, comp); - } - else - { - response = AESHelper(V2KEY, V2IV, comp); - } + response = AESHelper(V2KEY, V2IV, comp); } catch (Exception ex) { diff --git a/SPHDecode/Model/MainWindowModel.cs b/SPHDecode/Model/MainWindowModel.cs index 7dcf8b2..028abe9 100644 --- a/SPHDecode/Model/MainWindowModel.cs +++ b/SPHDecode/Model/MainWindowModel.cs @@ -91,7 +91,7 @@ private void OndecryptExecute() File.WriteAllBytes(dstFile, decode); MessageBox.Show("config decrypted successfully", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information); } - } + } public MainWindowModel() {