/// <summary> /// Loads an object from an XML file in Document format. /// </summary> /// <example> /// <code> /// serializableObject = ObjectXMLSerializer<SerializableObject>.Load(@"C:\XMLObjects.xml"); /// </code> /// </example> /// <param name="path">Path of the file to load the object from.</param> /// <returns>Object loaded from an XML file in Document format.</returns> public static T Load(string path) { T serializableObject = null; try { if (!KnowledgeMatrix.Framework.Utility.IsAdmin()) { FileCryptography.entropy = null; string path1 = path.Replace(".txt", "1.txt"); FileCryptography.FileName = path; FileCryptography.entropy = UnicodeEncoding.ASCII.GetBytes(KnowledgeMatrix.Properties.Settings.Default.ProductKey); FileCryptography.DoDecrypt(); string decryptedData = FileCryptography.decryptedData; File.WriteAllText(path1, decryptedData); serializableObject = LoadFromDocumentFormat(null, path1, null); File.Delete(path1); } else { serializableObject = LoadFromDocumentFormat(null, path, null); } } catch (Exception ex) { LogEntry.WriteLog(ex, "File Reading Exception : " + path); } return(serializableObject); }
private string ValidateImport(string strDestFile) { string decryptedData = null; //Check whether we can open the file OpenFileDialog objFile = new OpenFileDialog(); DialogResult resultdia = new DialogResult(); if (strDestFile == null) { resultdia = objFile.ShowDialog(); // Show the dialog. } else { objFile.FileName = strDestFile; } if (strDestFile != null || resultdia == DialogResult.OK) // Test result. { string file = objFile.FileName; //TO DO FileCryptography.DoDecrypt(file, KnowledgeMatrix.Properties.Settings.Default.ProductKey); decryptedData = FileCryptography.decryptedData; if (string.IsNullOrEmpty(decryptedData)) { MessageBox.Show("File is invalid"); } } return(decryptedData); }
public bool ValidateLicense() { FileCryptography.DoDecrypt(filename, null); string decryptedData = FileCryptography.decryptedData; if (!string.IsNullOrEmpty(decryptedData)) { string[] prodCatalog = decryptedData.Split('%'); string[] strLic = prodCatalog[0].ToString().Split('|');; // decryptedData.Split('|'); // if ((name == strLic[0]) && (email == strLic[1]) && (licensekey == strLic[2]) && (EntropyGenerator.GetSystemInfo("") == strLic[3])) if ((name == strLic[0]) && (email == strLic[1]) && (licensekey == strLic[2])) { KnowledgeMatrix.Properties.Settings.Default.IP = EntropyGenerator.GetIPForMachine(); KnowledgeMatrix.Properties.Settings.Default.Authenicated = "true"; KnowledgeMatrix.Properties.Settings.Default.Setting = EntropyGenerator.GetSystemInfo(""); KnowledgeMatrix.Properties.Settings.Default.ProductKey = strLic[4]; KnowledgeMatrix.Properties.Settings.Default.DateOfActivation = DateTime.Now; KnowledgeMatrix.Properties.Settings.Default.Save(); FileCryptography.encryptedData = prodCatalog[1]; FileCryptography.entropy = EntropyGenerator.GetKeyBytesForMachine(); FileCryptography.FileName = KnowledgeMatrix.Framework.Utility.XML_QUESTION_NAME; FileCryptography.DoEncrypt(); // FileCryptography.DoEncrypt(prodCatalog[1], KnowledgeMatrix.Framework.Utility.XML_QUESTION_NAME, null); return(true); } else { KnowledgeMatrix.Properties.Settings.Default.IP = "0.0.0.0"; KnowledgeMatrix.Properties.Settings.Default.Authenicated = "false"; KnowledgeMatrix.Properties.Settings.Default.Setting = ""; KnowledgeMatrix.Properties.Settings.Default.ProductKey = ""; KnowledgeMatrix.Properties.Settings.Default.DateOfActivation = DateTime.MaxValue; KnowledgeMatrix.Properties.Settings.Default.LastAccessedDate = DateTime.MaxValue; KnowledgeMatrix.Properties.Settings.Default.Save(); return(false); } } else { KnowledgeMatrix.Properties.Settings.Default.IP = "0.0.0.0"; KnowledgeMatrix.Properties.Settings.Default.Authenicated = "false"; KnowledgeMatrix.Properties.Settings.Default.Setting = ""; KnowledgeMatrix.Properties.Settings.Default.ProductKey = ""; KnowledgeMatrix.Properties.Settings.Default.DateOfActivation = DateTime.MaxValue; KnowledgeMatrix.Properties.Settings.Default.LastAccessedDate = DateTime.MaxValue; KnowledgeMatrix.Properties.Settings.Default.Save(); return(false); } }
private void ImpLicFile_Click(object sender, EventArgs e) { DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog. if (result == DialogResult.OK) // Test result.z { string file = openFileDialog1.FileName; FileCryptography.DoDecrypt(file, KnowledgeMatrix.Properties.Settings.Default.RegistrationKey); string decryptedData = FileCryptography.decryptedData; string[] prodCatalog = decryptedData.Split('|'); txtName.Text = prodCatalog[0]; txtEmail.Text = prodCatalog[1]; txtOrganisation.Text = prodCatalog[2]; txtPhone.Text = prodCatalog[3]; txtIP.Text = prodCatalog[5]; } }