public static async Task <bool> InterpretData(byte[] encryptedData) { bool result = false; try { Task taskAction = null; byte[] realDataEncrypted = new byte[encryptedData.Length - actionBytesCount]; Buffer.BlockCopy(encryptedData, 0, realDataEncrypted, 0, realDataEncrypted.Length); byte[] actionBytes = new byte[20]; Buffer.BlockCopy(encryptedData, encryptedData.Length - actionBytesCount, actionBytes, 0, actionBytes.Length); string action = Encoding.UTF8.GetString(actionBytes); string fileExtension; string dataEncripted = Encoding.UTF8.GetString(realDataEncrypted); byte[] realDataDecrypted = SecurityController.DESDecrypt(realDataEncrypted, "susta250", false, false); if (action.Contains(Sistem.GetActionTag((int)Sistem.EnumActionTags.FILE))) { int lastIdxOfDot = action.LastIndexOf("."); fileExtension = action.Substring(lastIdxOfDot, action.Length - lastIdxOfDot).Replace(">", "").Replace("\0", ""); taskAction = Task.Run(() => result = FileDataArrival(realDataDecrypted, fileExtension).Result); } if (action.Contains(Sistem.GetActionTag((int)Sistem.EnumActionTags.SQLMS))) { taskAction = Task.Run(() => result = SqlCommandExecute(realDataDecrypted, action).Result); } else if (action.Contains(Sistem.GetActionTag((int)Sistem.EnumActionTags.SQLPL))) { taskAction = Task.Run(() => result = OracleCommandExecute(realDataDecrypted, action).Result); } else { result = false; } if (taskAction != null) { taskAction.Wait(); taskAction.Dispose(); } } catch (Exception ex) { Sistem.WriteLog(ex, "InterpretData(byte[] encryptedData)", true); } return(result); }
private bool LoadConfigs() { try { string fileName = Directory.GetCurrentDirectory() + @"\Error " + DateTime.Now.ToShortDateString().Replace("/", "-") + ".log"; if (!File.Exists(fileName)) { File.Create(fileName); } swErrorWriter = new StreamWriter(fileName); string configFilePath = xmlPath; if (File.Exists(configFilePath)) { XmlDocument xmlConfig = new XmlDocument(); xmlConfig.Load(configFilePath); foreach (XmlNode tag in xmlConfig.ChildNodes) { if (tag.Name == enuConfig.Config.ToString()) { foreach (XmlNode item in tag.ChildNodes) { if (item.InnerText == "Sistem") { foreach (XmlNode item2 in item.ChildNodes) { int tagCount; if (item2.InnerText == "LogTags") { tagCount = 0; LogTags = new string[item2.ChildNodes.Count]; foreach (XmlNode item3 in item2.ChildNodes) { LogTags[tagCount] = item3.InnerText; tagCount++; } } if (item2.InnerText == "ActionTags") { tagCount = 0; ActionTags = new string[item2.ChildNodes.Count]; foreach (XmlNode item3 in item2.ChildNodes) { ActionTags[tagCount] = item3.InnerText; tagCount++; } } } } else if (item.Name == enuConfig.Oracle.ToString()) { //ORACLE ENVIROMENT foreach (XmlNode childnode2 in item.ChildNodes) { switch (childnode2.Name) { case "host": OraHost = childnode2.InnerText; break; case "server_port": OraPort = childnode2.InnerText; break; case "service_name": OraServicename = childnode2.InnerText; break; case "user_name": OraUser = childnode2.InnerText; break; case "password": if (!string.IsNullOrEmpty(childnode2.InnerText)) { OraPassword = SecurityController.RSADecryption(childnode2.InnerText); } else { OraPassword = string.Empty; } break; } } } else if (item.Name == enuConfig.SQL.ToString()) { //SQL ENVIROMENT foreach (XmlNode childnode2 in item.ChildNodes) { switch (childnode2.Name) { case "network_library": SqlNetworkLibrary = childnode2.InnerText; break; case "host": SqlHost = childnode2.InnerText; break; case "server_port": SqlPort = childnode2.InnerText; break; case "database_name": SqlDatabase = childnode2.InnerText; break; case "user_name": SqlUser = childnode2.InnerText; break; case "password": SqlPassword = childnode2.InnerText; break; case "database_path": if (File.Exists(childnode2.InnerText)) { SqlLocalDatabaseNamePath = childnode2.InnerText; } else { WriteLog("The specified path for the local sql database does not exists.", "LoadConfigs()", true, false, true, ConsoleColor.Red); } break; } } } } } } } else { // CREATE XML CONFIG FILE StreamWriter sw = new StreamWriter(xmlPath); sw.WriteLine("<?xml version=" + '"' + "1.0" + '"' + "encoding =" + '"' + "utf - 8" + '"' + "?> "); sw.WriteLine("<Config>"); sw.WriteLine(""); sw.WriteLine(" <Sistem> "); sw.WriteLine(" <LogTags> "); sw.WriteLine(" <logTag1>[Error] </logTag1> "); sw.WriteLine(" <logTag2>[Server] </logTag2> "); sw.WriteLine(" <logTag3>[Info] </logTag3> "); sw.WriteLine(" <logTag4>[SQL] </logTag4> "); sw.WriteLine(" <logTag5>[SistemLog] </logTag5> "); sw.WriteLine(" <logTag6>[Cryptography] </logTag6> "); sw.WriteLine(" <logTag7>[CryptographycError] </logTag7>"); sw.WriteLine(" </LogTags> "); sw.WriteLine(" <ActionTags> "); sw.WriteLine(" <ActionTag1></ActionTag1> "); sw.WriteLine(" <ActionTag2></ActionTag2> "); sw.WriteLine(" <ActionTag3></ActionTag3> "); sw.WriteLine(" </ActionTags> "); sw.WriteLine(" </Sistem> "); sw.WriteLine(""); sw.WriteLine(" <Oracle>"); sw.WriteLine(" <host></host>"); sw.WriteLine(" <server_port></server_port>"); sw.WriteLine(" <service_name></service_name>"); sw.WriteLine(" <user_name></user_name>"); sw.WriteLine(" <password></password>"); sw.WriteLine(" </Oracle>"); sw.WriteLine(""); sw.WriteLine(" <SQL>"); sw.WriteLine(" <host>latx24.nam.nsroot.net</host>"); sw.WriteLine(" <server_port>1433</server_port>"); sw.WriteLine(" <database_name>SIT11G</database_name>"); sw.WriteLine(" <user_name>PRISM9</user_name>"); sw.WriteLine(" <password>PRISM9</password>"); sw.WriteLine(" <network_library></network_library>"); sw.WriteLine(" </SQL>"); sw.WriteLine(""); sw.WriteLine("</Config>"); sw.Close(); } return(CheckConfigProperties()); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }