public static void DecodeViewState(byte[] protectedData, string strMachineKeysFilePath, string strValidationAlgorithm, string strDecryptionAlgorithm, string modifier, string strPurpose) { if (File.Exists(strMachineKeysFilePath)) { Console.Write("\n\nDecode process start!!\n\n"); string[] machineKeys = File.ReadAllLines(strMachineKeysFilePath); int nIndex = 1; foreach (string strLine in machineKeys) { Console.ForegroundColor = ConsoleColor.Blue; Console.Write("\rPocessing machinekeys : {0}/{1}....", nIndex++, machineKeys.Length); string[] values = strLine.Split(','); string strValidationKey = values[0]; string strDecryptionKey = values[1]; string strDecodedData = ViewStateHelper.DecodeData(strValidationKey, strValidationAlgorithm, protectedData, modifier); if (!String.IsNullOrEmpty(strDecodedData)) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\n\nKeys found!!"); Console.WriteLine("------------"); Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("DecryptionKey:" + strDecryptionKey); Console.WriteLine("ValidationKey:" + strValidationKey); DataWriter.WriteKeysToFile(strValidationKey, strDecryptionKey, strValidationAlgorithm, strDecryptionAlgorithm, null); DataWriter.WritePurposeToFile(strPurpose); Console.WriteLine("\n\nEncodedDataWithoutHash:" + strDecodedData); Console.ResetColor(); break; } } } }
public static bool DecodeViewState(byte[] protectedData, string strMachineKeysFilePath, string modifier, string strPurpose) { bool bFound = false; if (File.Exists(strMachineKeysFilePath)) { Console.Write("\n\nDecode process start!!\n\n"); string[] machineKeys = File.ReadAllLines(strMachineKeysFilePath); foreach (string strDecryptionAlgorithm in ContantValue.arrayDecryptionAlgo) { foreach (string strValidationAlgorithm in ContantValue.arrayValidationAlgo) { int nIndex = 1; foreach (string strLine in machineKeys) { try { Console.ForegroundColor = ConsoleColor.Blue; Console.Write("\rPocessing machinekeys {0},{1}: {2}/{3}..............", strDecryptionAlgorithm, strValidationAlgorithm, nIndex++, machineKeys.Length); string[] values = strLine.Split(','); string strValidationKey = values[0]; string strDecryptionKey = values[1]; string strDecodedData = ViewStateHelper.DecodeData(strValidationKey, strValidationAlgorithm, protectedData, modifier); if (!String.IsNullOrEmpty(strDecodedData)) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\n\nKeys found!!"); Console.WriteLine("------------"); Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("DecryptionKey:" + strDecryptionKey); Console.WriteLine("ValidationKey:" + strValidationKey); DataWriter.WriteKeysToFile(strValidationKey, strDecryptionKey, strValidationAlgorithm, strDecryptionAlgorithm, null); DataWriter.WritePurposeToFile(strPurpose); Console.WriteLine("\n\nEncodedDataWithoutHash:" + strDecodedData); Console.ResetColor(); bFound = true; break; } } catch (Exception e) { Console.WriteLine("Error Decoding ViewState: " + e); } } if (bFound) { break; } } if (bFound) { break; } } } else { Console.ForegroundColor = ConsoleColor.Red; Console.Write("\n\nKey path file {0} not found!!\n\n", strMachineKeysFilePath); Console.ResetColor(); } return(bFound); }