using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Web; using System.Xml; namespace Neo.Legitimate.LTPSWebService.Data { public class LTPSApplication { private LTPSApplication() { } public static string Verify(string password, string data) { string result; if (!LTPSApplication.ValidPassword(password)) { result = null; } else { XmlDocument xmlDoc = LTPSApplication.DecryptXml(data); LTPSOperatingLicence ol = new LTPSOperatingLicence(xmlDoc.SelectSingleNode("OperatingLicence") as XmlElement); ol.Verify(); result = LTPSApplication.Encrypt(xmlDoc.OuterXml); } return result; } public static string Submit(string password, string data) { string result; if (!LTPSApplication.ValidPassword(password)) { result = null; } else { XmlDocument xmlDoc = LTPSApplication.DecryptXml(data); LTPSOperatingLicence ol = new LTPSOperatingLicence(xmlDoc.SelectSingleNode("OperatingLicence") as XmlElement); ol.Create(null); result = LTPSApplication.Encrypt(xmlDoc.OuterXml); } return result; } public static string Query(string password, string data) { string result; if (!LTPSApplication.ValidPassword(password)) { result = null; } else { XmlDocument xmlCommand = LTPSApplication.DecryptXml(data); LTPSDataBroker db = new LTPSDataBroker(); XmlDocument xmlResult = db.Execute(xmlCommand); result = LTPSApplication.Encrypt(xmlResult.OuterXml); } return result; } private static string Encrypt(string plainText) { return CryptoProvider.Encrypt(ConfigurationManager.AppSettings["RijndaelKey"], ConfigurationManager.AppSettings["RijndaelIV"], plainText); } private static string Decrypt(string cipher) { return CryptoProvider.Decrypt(ConfigurationManager.AppSettings["RijndaelKey"], ConfigurationManager.AppSettings["RijndaelIV"], cipher); } private static XmlDocument DecryptXml(string xmlCipher) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(LTPSApplication.Decrypt(xmlCipher)); return xmlDoc; } private static bool ValidPassword(string password) { return ConfigurationManager.AppSettings["Password"] == LTPSApplication.Decrypt(password); } } }