/// <summary> /// LoadFromCache method implementation /// </summary> private static SIDsParametersRecord LoadFromCache() { SIDsParametersRecord config = null; if (!File.Exists(SystemUtilities.SystemCacheFile)) { return(null); } XmlConfigSerializer xmlserializer = new XmlConfigSerializer(typeof(SIDsParametersRecord)); using (FileStream fs = new FileStream(SystemUtilities.SystemCacheFile, FileMode.Open, FileAccess.Read)) { byte[] bytes = new byte[fs.Length]; int n = fs.Read(bytes, 0, (int)fs.Length); fs.Close(); byte[] byt = null; using (AESSystemEncryption aes = new AESSystemEncryption()) { byt = aes.Decrypt(bytes); } using (MemoryStream ms = new MemoryStream(byt)) { using (StreamReader reader = new StreamReader(ms)) { config = (SIDsParametersRecord)xmlserializer.Deserialize(ms); } } } return(config); }
/// <summary> /// ReadConfigurationForCache method implementation /// </summary> private byte[] ReadConfigurationForCache() { MFAConfig config = CFGUtilities.ReadConfiguration(); XmlConfigSerializer xmlserializer = new XmlConfigSerializer(typeof(MFAConfig)); MemoryStream stm = new MemoryStream(); using (StreamReader reader = new StreamReader(stm)) { xmlserializer.Serialize(stm, config); stm.Position = 0; return(XORUtilities.XOREncryptOrDecrypt(stm.ToArray(), XORUtilities.XORKey)); } }
/// <summary> /// WriteToCache method implementation /// </summary> private static void WriteToCache(SIDsParametersRecord config) { XmlConfigSerializer xmlserializer = new XmlConfigSerializer(typeof(SIDsParametersRecord)); MemoryStream stm = new MemoryStream(); using (StreamReader reader = new StreamReader(stm)) { xmlserializer.Serialize(stm, config); stm.Position = 0; byte[] byt = null; using (AESSystemEncryption aes = new AESSystemEncryption()) { byt = aes.Encrypt(stm.ToArray()); } using (FileStream fs = new FileStream(SystemUtilities.SystemCacheFile, FileMode.Create, FileAccess.ReadWrite)) { fs.Write(byt, 0, byt.Length); fs.Close(); } return; } }
/// <summary> /// GetConfig method implementation /// </summary> private static byte[] GetConfig(MFAConfig config) { using (AESSystemEncryption MSIS = new AESSystemEncryption()) { config.KeysConfig.XORSecret = MSIS.Encrypt(config.KeysConfig.XORSecret); config.Hosts.ActiveDirectoryHost.Password = MSIS.Encrypt(config.Hosts.ActiveDirectoryHost.Password); config.MailProvider.Password = MSIS.Encrypt(config.MailProvider.Password); }; XmlConfigSerializer xmlserializer = new XmlConfigSerializer(typeof(MFAConfig)); MemoryStream stm = new MemoryStream(); using (StreamReader reader = new StreamReader(stm)) { xmlserializer.Serialize(stm, config); stm.Position = 0; byte[] bytes = null; using (AESSystemEncryption aes = new AESSystemEncryption()) { bytes = aes.Encrypt(stm.ToArray()); } return(bytes); } }
/// <summary> /// WriteConfigurationToCache method implementation /// </summary> internal void WriteConfigurationToCache(byte[] config) { try { using (FileStream fs = new FileStream(CFGUtilities.ConfigCacheFile, FileMode.Create, FileAccess.ReadWrite)) { fs.Write(config, 0, config.Length); fs.Close(); } if (SIDs.Loaded) { XmlConfigSerializer xmlserializer = new XmlConfigSerializer(typeof(SIDsParametersRecord)); MemoryStream stm = new MemoryStream(); byte[] bytes = null; using (StreamReader reader = new StreamReader(stm)) { xmlserializer.Serialize(stm, SIDs.GetSIDs()); stm.Position = 0; using (AESSystemEncryption aes = new AESSystemEncryption()) { bytes = aes.Encrypt(stm.ToArray()); } } using (FileStream fs = new FileStream(SystemUtilities.SystemCacheFile, FileMode.Create, FileAccess.ReadWrite)) { fs.Write(bytes, 0, bytes.Length); fs.Close(); } } } catch (Exception e) { _log.WriteEntry(string.Format("Error on WebAdminService Service WriteConfigurationToCache method : {0}.", e.Message), EventLogEntryType.Error, 2010); throw e; } }