/// <summary> /// Attempts to load and store the encryption key and initialization vector in memory /// if a key and IV is not recovered, it will generate a new key. /// </summary> /// <returns>False, if no key was located. True if key if found</returns> public bool LoadOrCreateEncryptionKey() { var key = AppDomain.CurrentDomain.BaseDirectory + Constants.FilePaths.Key; using (var fileStream = File.Open(key, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { using (StreamReader sr = new StreamReader(fileStream, true)) { EncryptionKey = sr.ReadToEnd(); } } var initializationVector = AppDomain.CurrentDomain.BaseDirectory + Constants.FilePaths.InitializationVector; using (var fileStream = File.Open(initializationVector, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { using (StreamReader sr = new StreamReader(fileStream, true)) { InitilizationVector = sr.ReadToEnd(); } } if (string.IsNullOrEmpty(EncryptionKey) || string.IsNullOrEmpty(InitilizationVector)) { Security.AES AES_SecurityPackage = new Security.AES(); AES_SecurityPackage.GenerateNewKey(); return(false); } return(true); }