private void btnFileDecrypt_Click(object sender, EventArgs e) { try { if (comboBox1.SelectedItem == null) { txtFileToDecrypt.Text = ""; MessageBox.Show("select the usb original where the file was put. Otherwise can't decrypt"); return; } UsbDrive ud = (UsbDrive)comboBox1.SelectedItem; string secretKey = ud.serialNumber; EncryptDecrypt.MyEncryptor enc = new EncryptDecrypt.MyEncryptor(secretKey); enc.Decrypt(fileToDecrypt, decryptedFileName); MessageBox.Show("File decrypted successfully."); } catch (Exception ex) { //Console.WriteLine(ex.Message); //MessageBox.Show("This isn't the USB drive that was used to encrypt this file. Try selecting another."); MessageBox.Show(ex.Message); } }
private void btnFileEncrypt_Click(object sender, EventArgs e) { try { if (comboBox1.SelectedItem == null) { MessageBox.Show("No USB Flash drive attached. Please attach one."); return; } UsbDrive selectedUsb = (UsbDrive)comboBox1.SelectedItem; string secretKey = selectedUsb.serialNumber; // the usb serial number is used as the private key EncryptDecrypt.MyEncryptor enc = new EncryptDecrypt.MyEncryptor(secretKey); enc.Encrypt(fileToEncrypt, selectedUsb.driveLetter + encryptedFileName); // MessageBox.Show(fileToEncrypt + " || " + selectedUsb.driveLetter +"\\"+ encryptedFileName); return; MessageBox.Show("File Encrypted Successfully."); //enc.Encrypt(txtFileToEncrypt.Text, "D:\\Personal"+ "\\"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }