private void FormMain_Load(object sender, EventArgs e) { // start the encryption thread pool to speed up the analyzer - this is also the first access to the native // "TrueCrypt.dll" and therefore an exception may occur when the library cannot be loaded try { TrueCrypt.EncryptionThreadPoolStart(Environment.ProcessorCount); } catch (Exception ex) { if (ex is DllNotFoundException || ex is EntryPointNotFoundException) { MessageBox.Show(this, PageContext.GetInstance().GetResourceString("LoadTrueCryptDllFailed"), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop); silentExit = true; Close(); return; } throw; } // try to open the TestCrypt driver just to test whether the driver can be opened try { TrueCrypt.OpenDriver(); } catch (TrueCrypt.TrueCryptException ex) { // the TestCrypt driver could not be opened - most probably this is caused by a 64-bit operating system // which requires digitally signed drivers string msg; switch (ex.Cause) { case TrueCrypt.TrueCryptException.ExceptionCause.DriverLoadFailed: // check whether loading the driver failed due to the missing digital driver signature if (((uint)ex.ErrorCode == 0x80004005) && Wow.Is64BitOperatingSystem && Wow.IsOSAtLeast(Wow.OSVersion.WIN_VISTA)) { // missing digital driver signature notifyIcon.BalloonTipClicked += notifyIcon_BalloonTipClicked; notifyIcon.BalloonTipTitle = PageContext.GetInstance().GetResourceString("LoadTestCryptDriverFailedTitle"); notifyIcon.BalloonTipText = PageContext.GetInstance().GetResourceString("DriverSignatureEnforcement"); notifyIcon.ShowBalloonTip(30000); } else { // another error has occurred msg = string.Format(PageContext.GetInstance().GetResourceString("LoadTestCryptDriverFailed"), ex.ErrorCode, ex.Message); MessageBox.Show(this, msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); } break; case TrueCrypt.TrueCryptException.ExceptionCause.DriverOpenFailed: default: msg = string.Format(PageContext.GetInstance().GetResourceString("OpenTestCryptDriverFailed"), ex.ErrorCode, ex.Message); MessageBox.Show(this, msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } } }
private void mnuDismountAll_Click(object sender, EventArgs e) { try { TrueCrypt.DismountAll(); } catch (TrueCrypt.TrueCryptException ex) { MessageBox.Show(this, string.Format("Unable to dismount all volumes: {0}", ex.Message), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public EncryptionScenarioViewModel( DESEncryption desEncryption, AESEncryption aesEncryption, TrueCrypt trueCrypt) : base() { DisplayName = "Encryption"; Scenarios.Add(desEncryption); Scenarios.Add(aesEncryption); Scenarios.Add(trueCrypt); }
/// <summary> /// "Click" event handler of the "OK" button. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs" /> instance containing the event data.</param> private void btnAccept_Click(object sender, EventArgs e) { Nullable <TrueCrypt.Password> password = page.Password; if (password.HasValue) { using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { byte[] data = new byte[TrueCrypt.TC_VOLUME_HEADER_GROUP_SIZE]; int count = fs.Read(data, 0, data.Length); fs.Close(); int offset = 0; TrueCrypt.Password pwd = password.Value; while (offset + TrueCrypt.TC_VOLUME_HEADER_SIZE_LEGACY <= count) { Array.Copy(data, offset, data, 0, TrueCrypt.TC_VOLUME_HEADER_SIZE_LEGACY); TrueCrypt.CRYPTO_INFO cryptoInfo = new TrueCrypt.CRYPTO_INFO(); if (0 == TrueCrypt.ReadVolumeHeader(false, data, ref pwd, IntPtr.Zero, ref cryptoInfo)) { CryptoInfo = cryptoInfo; break; } offset += TrueCrypt.TC_VOLUME_HEADER_SIZE; } if (offset + TrueCrypt.TC_VOLUME_HEADER_SIZE_LEGACY <= count) { // select the default keyboard layout and close the dialog (after setting the result of the dialog) InputLanguage.CurrentInputLanguage = InputLanguage.DefaultInputLanguage; DialogResult = DialogResult.OK; Close(); } else { MessageBox.Show(PageContext.GetInstance().GetResourceString("PasswordIncorrect"), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } }