public static string DESEncrypt(string ip1, string ip2, string ip3, string time1, string time2) { if (ip1 == "") { ip1 = "ip1"; } if (ip2 == "") { ip2 = "ip2"; } if (ip3 == "") { ip3 = "ip3"; } if (time1 == "") { time1 = "time1"; } if (time2 == "") { time2 = "time2"; } string input = ip1 + "," + ip2 + "," + ip3 + "," + time1 + "," + time2; byte[] bytesDESKey = ASCIIEncoding.ASCII.GetBytes(""); byte[] bytesDESSrc = ASCIIEncoding.ASCII.GetBytes(input); DesKey des = new DesKey(bytesDESKey); des.encrypt(bytesDESSrc); return(Convert.ToBase64String(bytesDESSrc)); }
public static string DESDecrypt(string src, string k) { byte[] bytesDESKey = ASCIIEncoding.ASCII.GetBytes(k); byte[] bytesDESSrc = ASCIIEncoding.ASCII.GetBytes(src); DesKey des = new DesKey(bytesDESKey); des.decrypt(bytesDESSrc); return(Convert.ToBase64String(bytesDESSrc)); }
public static void ReadConfig() { XmlDocument xDoc = new XmlDocument(); Assembly asm = Assembly.GetExecutingAssembly(); //string fileName = asm.Location.ToLower().Replace(".dll", ".app.exe.config"); string fileName = asm.Location.ToLower() + ".config"; xDoc.Load(fileName); Framework.Environment.ServerIP = xDoc.SelectSingleNode("//userSettings//setting[@name='ServerIP']//value").InnerText; Framework.Environment.LocalCommIP = xDoc.SelectSingleNode("//userSettings//setting[@name='LocalCommIP']//value").InnerText; Framework.Environment.GisMapPath = xDoc.SelectSingleNode("//userSettings//setting[@name='GisMapPath']//value").InnerText; if (Framework.Environment.LocalCommIP == "127.0.0.1") { string hostname = System.Net.Dns.GetHostName(); System.Net.IPAddress[] ips = System.Net.Dns.GetHostAddresses(hostname); foreach (var item in ips) { if (item.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { Framework.Environment.LocalCommIP = item.ToString(); break; } } } Framework.Environment.UploadAbility = Convert.ToUInt32(xDoc.SelectSingleNode("//userSettings//setting[@name='UploadAbility']//value").InnerText); Framework.Environment.BehaviourDataReceivePort = Convert.ToUInt32(xDoc.SelectSingleNode("//userSettings//setting[@name='behaviourDataReceivePort']//value").InnerText); Framework.Environment.TrafficEventDataReceivePort = Convert.ToUInt32(xDoc.SelectSingleNode("//userSettings//setting[@name='trafficEventDataReceivePort']//value").InnerText); Framework.Environment.AlarmReceivePort = Convert.ToUInt32(xDoc.SelectSingleNode("//userSettings//setting[@name='AlarmReceivePort']//value").InnerText); Framework.Environment.SavePassword = Convert.ToBoolean(xDoc.SelectSingleNode("//userSettings//setting[@name='SavePassword']//value").InnerText); if (Framework.Environment.CurUserInfo == null) { Framework.Environment.CurUserInfo = new UserInfo(); } Framework.Environment.CurUserInfo.UserName = xDoc.SelectSingleNode("//userSettings//setting[@name='UserName']//value").InnerText; Framework.Environment.CurUserInfo.UserPwd = DesKey.Decrypt(xDoc.SelectSingleNode("//userSettings//setting[@name='Password']//value").InnerText); Framework.Environment.VideoSavePath = Path.Combine(Path.GetDirectoryName(asm.Location), "Video"); if (!Directory.Exists(Framework.Environment.VideoSavePath)) { Directory.CreateDirectory(Framework.Environment.VideoSavePath); } Framework.Environment.PictureSavePath = Path.Combine(Path.GetDirectoryName(asm.Location), "Picture"); if (!Directory.Exists(Framework.Environment.PictureSavePath)) { Directory.CreateDirectory(Framework.Environment.PictureSavePath); } }
public byte[] GetDesArray() { var retValue = new List <byte>(); var chars = DesKey.ToCharArray(); for (var i = 0; i + 1 < chars.Length; i += 2) { var hex = "" + chars[i] + chars[i + 1]; retValue.Add((byte)int.Parse(hex, System.Globalization.NumberStyles.HexNumber)); } return(retValue.ToArray()); }
public static bool SaveConfig() { try { XmlDocument xDoc = new XmlDocument(); Assembly asm = Assembly.GetExecutingAssembly(); //string fileName = asm.Location.ToLower().Replace(".dll", ".app.exe.config"); string fileName = asm.Location.ToLower() + ".config"; xDoc.Load(fileName); XmlNode xNode = xDoc.SelectSingleNode("//userSettings"); XmlElement xElemServerIP = (XmlElement)xNode.SelectSingleNode("//setting[@name='ServerIP']"); xElemServerIP.SelectSingleNode("value").InnerText = Framework.Environment.ServerIP; XmlElement xElemSavePassword = (XmlElement)xNode.SelectSingleNode("//setting[@name='SavePassword']"); xElemSavePassword.SelectSingleNode("value").InnerText = Framework.Environment.SavePassword.ToString(); XmlElement xElemUserName = (XmlElement)xNode.SelectSingleNode("//setting[@name='UserName']"); xElemUserName.SelectSingleNode("value").InnerText = Framework.Environment.CurUserInfo.UserName; XmlElement xElemPassword = (XmlElement)xNode.SelectSingleNode("//setting[@name='Password']"); if (!Framework.Environment.SavePassword) { xElemPassword.SelectSingleNode("value").InnerText = ""; } else { xElemPassword.SelectSingleNode("value").InnerText = DesKey.Encrypt(Framework.Environment.CurUserInfo.UserPwd); } xDoc.Save(fileName); //try //{ // s_Config = ConfigurationManager.OpenExeConfiguration(asm.Location); //} //catch (Exception ex) //{ // MyLog4Net.Container.Instance.Log.Error("OpenExeConfiguration error in Environment: ", ex); //} return(true); } catch { DevComponents.DotNetBar.MessageBoxEx.Show("配置文件损坏,系统参数可能无法保存。", Framework.Environment.PROGRAM_NAME, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } }
public static byte[] Decrypt(byte[] input, DesKey key) { return(Decrypt(input, key.Key, key.Iv)); }