Skip to content

Commit

Permalink
Merge branch 'v3'
Browse files Browse the repository at this point in the history
  • Loading branch information
Stricted committed Feb 16, 2017
2 parents 4a6fd48 + 8d8b11e commit f391219
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
26 changes: 18 additions & 8 deletions SPHDecode/Implementations/Cryptography.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,26 @@ 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[] { 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)
{
byte[] response;

try
{
byte[] data = AESHelper(clearText, true);
byte[] data;
try {
data = AESHelper(V3KEY, V3IV, clearText, true);
}
catch (Exception)
{
data = AESHelper(V2KEY, V2IV, clearText, true);
}

response = Zlib.DecompressData(data);
}
Expand Down Expand Up @@ -53,7 +63,7 @@ public static byte[] Encrypt(byte[] data)
{
byte[] comp = Zlib.CompressData(clearText);

response = AESHelper(comp);
response = AESHelper(V2KEY, V2IV, comp);
}
catch (Exception ex)
{
Expand All @@ -65,7 +75,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();

Expand All @@ -78,8 +88,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);
Expand Down
12 changes: 6 additions & 6 deletions SPHDecode/Model/MainWindowModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit f391219

Please sign in to comment.