コード例 #1
0
ファイル: Main.cs プロジェクト: janindu2r/cryptor
        public void LoadDrives()  //working one final one
        {
            try
            {
                USBCollection = new ManagementObjectSearcher("select * from Win32_DiskDrive where InterfaceType='USB'").Get();
                availableUsbs.Clear();
                comboBox1.Items.Clear();
                foreach (ManagementObject drive in USBCollection)
                {
                    foreach (ManagementObject partition in new ManagementObjectSearcher("ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" + drive["DeviceID"] + "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition").Get())
                    {
                        foreach (ManagementObject disk in new ManagementObjectSearcher("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" + partition["DeviceID"] + "'} WHERE AssocClass =Win32_LogicalDiskToPartition").Get())
                        {
                            UsbDrive ud = new UsbDrive();
                            ud.driveLabel   = (string)disk["VolumeName"];
                            ud.driveLetter  = (string)disk["Name"];
                            ud.modelInfo    = (string)drive["model"];
                            ud.serialNumber = (string)drive["SerialNumber"];

                            availableUsbs.Add(ud);

                            comboBox1.Items.Add(ud);
                            comboBox1.SelectedIndex = 0;
                        }
                    }
                }
            }
            catch (Exception)
            {
                LoadDrives();
            }
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: janindu2r/cryptor
        //System.Management.ManagementClass USBClass = new ManagementClass("Win32_DiskDrive");

        public Main()
        {
            USBCollection = new ManagementObjectSearcher("select * from Win32_DiskDrive where InterfaceType='USB'").Get();
            InitializeComponent();
            // PidVidMeth();
            LoadDrives();
            currentSelectedDrive = (UsbDrive)comboBox1.SelectedItem;
            //GetDriveLetters();
            //testMeth();

            //}
            // MyMethod();
        }
コード例 #3
0
ファイル: Main.cs プロジェクト: janindu2r/cryptor
        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);
            }
        }
コード例 #4
0
ファイル: Main.cs プロジェクト: janindu2r/cryptor
        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);
            }
        }
コード例 #5
0
ファイル: Main.cs プロジェクト: janindu2r/cryptor
 public Main()
 {
     InitializeComponent();
     LoadDrives();
     currentSelectedDrive = (UsbDrive)comboBox1.SelectedItem;
 }
コード例 #6
0
ファイル: Main.cs プロジェクト: janindu2r/cryptor
 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     currentSelectedDrive = (UsbDrive)comboBox1.SelectedItem;
 }
コード例 #7
0
ファイル: Main.cs プロジェクト: janindu2r/cryptor
        private void btnFileEncrypt_Click(object sender, EventArgs e)
        {
            try
            {
                if (comboBox1.SelectedItem == null)
                {
                    MessageBox.Show("No USB Flash drive attached. Please attach one.");
                    return;
                }
                if (filesToEncrypt.Count == 0)
                {
                    MessageBox.Show("Select one or more files.");
                    return;
                }
                else
                {
                    pb.ShowDialog();
                    if (!pb.pwordok)
                    {
                        return;
                    }
                }

                label4.Text = "Please Wait...";
                enabledisableComponents(false);
                label4.Enabled = true;

                UsbDrive    selectedUsb = (UsbDrive)comboBox1.SelectedItem;
                string      secretKey   = selectedUsb.serialNumber + pb.password;
                MyEncryptor enc         = new MyEncryptor(secretKey);


                foreach (string fileToEncrypt in filesToEncrypt)
                {
                    string encryptedFileName = getEncryptFileName(fileToEncrypt);

                    if (encryptedFileName == "")
                    {
                        MessageBox.Show("Invalid File : " + filesToEncrypt);
                        continue;
                    }

                    enc.Encrypt(fileToEncrypt, selectedUsb.driveLetter + encryptedFileName);


                    FileInfo ff = new FileInfo(selectedUsb.driveLetter + encryptedFileName);
                    File.SetAttributes(ff.FullName, FileAttributes.System);
                    File.SetAttributes(ff.FullName, FileAttributes.Hidden);
                }

                //Copying the decrypting module
                FileInfo fsrc  = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "TheDecryptor.exe");
                FileInfo fdest = new FileInfo(selectedUsb.driveLetter + @"\" + "TheDecryptor.exe");

                if (!fdest.Exists)
                {
                    fsrc.CopyTo(fdest.FullName);
                }

                enabledisableComponents(true);
                label4.Text = "";
                MessageBox.Show("All the files Encrypted Successfully.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #8
0
ファイル: Main.cs プロジェクト: janindu2r/cryptor
 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     currentSelectedDrive = (UsbDrive)comboBox1.SelectedItem;
     MessageBox.Show("Selected : " + currentSelectedDrive.serialNumber);
 }
コード例 #9
0
ファイル: Main.cs プロジェクト: janindu2r/cryptor
        //public void GetDriveLetters()
        //{
        //    DriveInfo[] drives = DriveInfo.GetDrives();

        //    foreach (DriveInfo d in drives)
        //    {
        //        try
        //        {
        //            listBox2.Items.Add(d.DriveType);
        //            listBox2.Items.Add(d.DriveFormat);
        //            listBox2.Items.Add(d.Name);
        //            listBox2.Items.Add(d.RootDirectory);
        //            listBox2.Items.Add(d.VolumeLabel);

        //            listBox2.Items.Add("");
        //        }
        //        catch (Exception e)
        //        {
        //            listBox2.Items.Add("");
        //            continue;

        //        }

        //    }
        //}

        //public void advnc()
        //{
        //    foreach (ManagementObject drive in new ManagementObjectSearcher("select * from Win32_DiskDrive where InterfaceType='USB'").Get())
        //    {
        //        foreach (ManagementObject partition in new ManagementObjectSearcher("ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" + drive["DeviceID"] + "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition").Get())
        //        {
        //            //foreach (ManagementObject partition in new ManagementObjectSearcher("ASSOCIATORS OF {Win32_DiskDrive.Model='" + "SanDisk Cruzer Contour USB Device" + "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition").Get())
        //            //if (drive["Model"].ToString() == "SanDisk Cruzer Contour USB Device")
        //            //{
        //            listBox1.Items.Add("Partition=" + partition["Name"]);

        //            // associate partitions with logical disks (drive letter volumes)
        //            foreach (ManagementObject disk in new ManagementObjectSearcher("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" + partition["DeviceID"] + "'} WHERE AssocClass =Win32_LogicalDiskToPartition").Get())
        //            {
        //                listBox1.Items.Add("Disk=" + disk["Name"]);
        //            }
        //            //}
        //        }
        //    }
        //}

        //public void PidVidMeth()
        //{
        //    ManagementObjectSearcher mosDisks = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");

        //    // Loop through each object (disk) retrieved by WMI

        //    foreach (ManagementObject moDisk in mosDisks.Get())
        //    {

        //        // Add the HDD to the list (use the Model field as the item's caption)

        //        listBox1.Items.Add(moDisk["model"].ToString());


        //    }



        //}

        //public void testMeth()
        //{
        //    ManagementObjectSearcher mosDisks = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");

        //    // Loop through each object (disk) retrieved by WMI

        //    foreach (ManagementObject moDisk in mosDisks.Get())
        //    {

        //        // Add the HDD to the list (use the Model field as the item's caption)

        //        foreach(PropertyData p in moDisk.Properties)
        //        {
        //            listBox3.Items.Add(p.Name+" "+p.Value);
        //        }


        //        listBox3.Items.Add("");
        //    }

        //}

        public void LoadDrives()  //working one final one
        {
            //USBClass = new ManagementClass("Win32_DiskDrive");
            //USBCollection = USBClass.GetInstances();
            //USBCollection = new ManagementObjectSearcher("select * from Win32_DiskDrive where InterfaceType='USB'").Get();


            foreach (ManagementObject drive in USBCollection)
            {
                //listBox1.Items.Add("Name : " + drive["model"]);
                try
                {
                    listBox1.Items.Add("Serial Num : " + drive["SerialNumber"].ToString());
                }
                catch (Exception)
                {
                    continue;
                }
                //listBox1.Items.Add("DeviceID : "+drive["deviceid"].ToString());
                //listBox1.Items.Add("MediaType : " + drive["MediaType"].ToString());
                //listBox1.Items.Add("Desc : " + drive["Description"].ToString());

                foreach (ManagementObject partition in new ManagementObjectSearcher("ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" + drive["DeviceID"] + "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition").Get())
                {
                    //foreach (ManagementObject partition in new ManagementObjectSearcher("ASSOCIATORS OF {Win32_DiskDrive.Model='" + "SanDisk Cruzer Contour USB Device" + "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition").Get())
                    //if (drive["Model"].ToString() == "SanDisk Cruzer Contour USB Device")
                    //{
                    //listBox1.Items.Add("Partition=" + partition["Label"]);
                    //foreach (PropertyData p in partition.Properties)
                    //{
                    //    listBox3.Items.Add(p.Name + " " + p.Value);
                    //}

                    // associate partitions with logical disks (drive letter volumes)
                    foreach (ManagementObject disk in new ManagementObjectSearcher("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" + partition["DeviceID"] + "'} WHERE AssocClass =Win32_LogicalDiskToPartition").Get())
                    {
                        //listBox1.Items.Add("Drive Letter : " + disk["Name"]);
                        //listBox1.Items.Add("Drive Label : " + disk["VolumeName"]);

                        //foreach (PropertyData p in disk.Properties)
                        //{
                        //    listBox3.Items.Add(p.Name + " " + p.Value);
                        //    //drive.Properties.Add("DriveLetter", disk["Name"]);
                        //}
                        UsbDrive ud = new UsbDrive();
                        ud.driveLabel   = (string)disk["VolumeName"];
                        ud.driveLetter  = (string)disk["Name"];
                        ud.modelInfo    = (string)drive["model"];
                        ud.serialNumber = (string)drive["SerialNumber"];

                        availableUsbs.Add(ud);

                        //comboBox1.Items.Add(drive["model"] + " " + disk["Name"] + " " + disk["VolumeName"]);
                        comboBox1.Items.Add(ud);
                        comboBox1.SelectedIndex = 0;

                        label2.Text = "availablr usbs : " + availableUsbs.Count.ToString();
                    }
                    //}
                }

                //   listBox1.Items.Add("Signature : " + usb["Signature"].ToString());


                //listBox1.Items.Add(usb.GetText(new TextFormat()));
                //Console.WriteLine(usb.GetText(new TextFormat()));

                //listBox1.Items.Add("Serial Num : "+usb["SerialNumber"].ToString());

                //string deviceId = usb["deviceid"].ToString();
                //Console.WriteLine(deviceId);
                //listBox1.Items.Add(deviceId);

                //int vidIndex = deviceId.IndexOf("VID_");
                //string startingAtVid = deviceId.Substring(vidIndex + 4); // + 4 to remove "VID_"
                //string vid = startingAtVid.Substring(0, 4); // vid is four characters long
                //Console.WriteLine("VID: " + vid);
                //listBox1.Items.Add("VID: " + vid);

                //int pidIndex = deviceId.IndexOf("PID_");
                //string startingAtPid = deviceId.Substring(pidIndex + 4); // + 4 to remove "PID_"
                //string pid = startingAtPid.Substring(0, 4); // pid is four characters long
                //Console.WriteLine("PID: " + pid);
                //listBox1.Items.Add("PID: " + pid);
            }
        }