public static byte[] Encrypt(this SystemEnvironment environment) { byte[] byteArray; System.Runtime.Serialization.Formatters.Binary.BinaryFormatter serializer = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); System.IO.MemoryStream memStream = new System.IO.MemoryStream(); serializer.Serialize(memStream, environment); // Set the position to the beginning of the stream. memStream.Seek(0, SeekOrigin.Begin); // Read the first 20 bytes from the stream. byteArray = new byte[memStream.Length]; memStream.Read(byteArray, 0, (int)memStream.Length); memStream.Close(); //加密 return(AESHelper.AesEncrypt(byteArray, AESHelper.AESKEY)); //return byteArray; }
/// <summary> /// 保存站点配置 /// </summary> /// <param name="siteShortName">站点短名</param> private static void SaveSiteConfig(string siteShortName) { if (!inis.ContainsKey(siteShortName)) { return; } IniData iniData = inis[siteShortName]; if (!iniData.Sections.Any()) { return; } string content = string.Empty, iv = content, siteini = $"{SitePacksPath}{siteShortName}.ini"; //写出指定站点配置并压缩 iniParser.WriteFile(siteini, iniData); content = File.ReadAllText(siteini); iv = RandomRNG(100000, 999999).ToString(); content = $"{iv}{AESHelper.AesEncrypt(content, aesKey, iv)}"; content = Convert.ToBase64String(LZ4Codec.Wrap(Encoding.UTF8.GetBytes(content))); File.WriteAllText(siteini, content); }