public void DecryptDB() { if (File.Exists(DBFileName) == false || new FileInfo(DBFileName).Length < 500) { this.Close(); return; } FileStream fileStream_ConnectingServiceXMLDB = null; try { MemoryStream memoryStream_XMLData = new MemoryStream(), memoryStream_DecryptedXMLData = new MemoryStream(), memoryStream_EncryptedXMLData = null; SHA256Managed sHA256Managed_obj = new SHA256Managed(); RijndaelManaged rijndaelManaged_obj = new RijndaelManaged(); CryptoStream cryptoStream_obj = null; fileStream_ConnectingServiceXMLDB = File.Open(DBFileName, FileMode.Open, FileAccess.Read); byte [] byteArray_ComputedXMLDataHash = new byte[32], byteArray_ComputedHashOfPasswordHash = new byte[32], byteArray_StoredXMLDataHash = new byte[32], byteArray_StoredHashOfPasswordHash = new byte[32], byteArray_DecompressedXMLData = null, byteArray_ComputedPasswordHash, byteArray_ConnectingServiceDBHeader = new byte[22], byteArray_EncryptedXMLData = new byte[fileStream_ConnectingServiceXMLDB.Length - 88]; byte byte_ToEncryptServerDataBase = 0, byte_ToCompressSettingsDataBase = 0; fileStream_ConnectingServiceXMLDB.Read(byteArray_ConnectingServiceDBHeader, 0, byteArray_ConnectingServiceDBHeader.Length); if (CommonMethods.AreBytesArraysEquals(System.Text.Encoding.Default.GetBytes("ConnectingServiceDB010"), byteArray_ConnectingServiceDBHeader) == false) { fileStream_ConnectingServiceXMLDB.Close(); MessageBox.Show(ServerStringFactory.GetString(124, MainForm.CurrentLanguage), ServerStringFactory.GetString(1, MainForm.CurrentLanguage)); this.Close(); return; } byte_ToEncryptServerDataBase = (byte)fileStream_ConnectingServiceXMLDB.ReadByte(); byte_ToCompressSettingsDataBase = (byte)fileStream_ConnectingServiceXMLDB.ReadByte(); fileStream_ConnectingServiceXMLDB.Read(byteArray_StoredXMLDataHash, 0, byteArray_StoredXMLDataHash.Length); fileStream_ConnectingServiceXMLDB.Read(byteArray_StoredHashOfPasswordHash, 0, byteArray_StoredHashOfPasswordHash.Length); if (byte_ToEncryptServerDataBase == 1) { byteArray_ComputedPasswordHash = sHA256Managed_obj.ComputeHash(System.Text.Encoding.Default.GetBytes(this.textBox_PasswordPromptForm_Password.Text)); byteArray_ComputedHashOfPasswordHash = sHA256Managed_obj.ComputeHash(byteArray_ComputedPasswordHash); if (CommonMethods.AreBytesArraysEquals(byteArray_ComputedHashOfPasswordHash, byteArray_StoredHashOfPasswordHash) == false) { MessageBox.Show(ServerStringFactory.GetString(126, MainForm.CurrentLanguage), ServerStringFactory.GetString(1, MainForm.CurrentLanguage), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } rijndaelManaged_obj.KeySize = 256; rijndaelManaged_obj.Key = byteArray_ComputedPasswordHash; rijndaelManaged_obj.IV = new byte[rijndaelManaged_obj.BlockSize / 8]; fileStream_ConnectingServiceXMLDB.Read(byteArray_EncryptedXMLData, 0, byteArray_EncryptedXMLData.Length); memoryStream_EncryptedXMLData = new MemoryStream(byteArray_EncryptedXMLData); cryptoStream_obj = new CryptoStream(memoryStream_EncryptedXMLData, rijndaelManaged_obj.CreateDecryptor(), CryptoStreamMode.Read); while (true) { int int_Byte = cryptoStream_obj.ReadByte(); if (int_Byte == -1) { break; } memoryStream_DecryptedXMLData.WriteByte((byte)int_Byte); } memoryStream_EncryptedXMLData.Close(); cryptoStream_obj.Flush(); cryptoStream_obj.Clear(); cryptoStream_obj.Close(); CommonEnvironment.EncryptSettingsDataBase = true; CommonEnvironment.LocalSecurityPassword = this.textBox_PasswordPromptForm_Password.Text; memoryStream_XMLData = new MemoryStream(memoryStream_DecryptedXMLData.ToArray()); memoryStream_DecryptedXMLData.Close(); } if (byte_ToCompressSettingsDataBase == 1) { byteArray_DecompressedXMLData = new YakSys.Compression.CommonEnvironment().Decompress(memoryStream_XMLData.ToArray(), false); memoryStream_XMLData = new MemoryStream(byteArray_DecompressedXMLData); CommonEnvironment.CompressSettingsDataBase = true; } else { CommonEnvironment.CompressSettingsDataBase = false; } fileStream_ConnectingServiceXMLDB.Close(); ConnectingServiceDBSupplier ConnectingServiceDBSupplier_obj = new ConnectingServiceDBSupplier(); ConnectingServiceDBSupplier_obj.RetriveServerSettingsData(memoryStream_XMLData); ObjCopy.obj_MainForm.SetUpServerSettingsFromDB(); memoryStream_XMLData.Close(); this.Close(); } catch (Exception) { MessageBox.Show(ServerStringFactory.GetString(125, MainForm.CurrentLanguage), ServerStringFactory.GetString(1, MainForm.CurrentLanguage)); } finally { fileStream_ConnectingServiceXMLDB.Close(); } }