示例#1
0
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            VirtualDriveCreator.UnmapDrive('X');
            System.IO.DirectoryInfo di = new DirectoryInfo(System.IO.Path.GetTempPath() + "cryptor");

            if (di.Exists)
            {
                foreach (FileInfo file in di.GetFiles())
                {
                    file.Delete();
                }
                foreach (DirectoryInfo dir in di.GetDirectories())
                {
                    dir.Delete(true);
                }

                System.IO.Directory.Delete(System.IO.Path.GetTempPath() + "cryptor");
            }
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                pb.ShowDialog();

                if (pb.pwordok)
                {
                    UsbDrive ud                  = (UsbDrive)comboBox1.SelectedItem;
                    string   secretKey           = ud.serialNumber + pb.password.Trim();
                    TheDecryptor.MyEncryptor enc = new TheDecryptor.MyEncryptor(secretKey);

                    foreach (FileInfo f in availableFiles)
                    {
                        string fileToDecrypt = f.FullName;
                        int    iPosition;
                        iPosition = fileToDecrypt.LastIndexOf(".ccp");
                        if ((iPosition == -1) || (iPosition != (fileToDecrypt.Length - 4)))
                        {
                            MessageBox.Show("Corrupt file :" + f + ". Moving to the nextfile.");
                            continue;
                        }

                        //strOutputFile = the file path minus the last 8 characters (.ccp)
                        string decryptedFileName = f.Name.Substring(0, fileToDecrypt.Length - 7);
                        //MessageBox.Show(decryptedFileName);
                        //Assign strOutputFile to the position after the last "\" in the path.
                        iPosition = decryptedFileName.LastIndexOf("ccp");
                        if (iPosition == -1)
                        {
                            decryptedFileName = decryptedFileName + ".dat";
                        }
                        else
                        {
                            decryptedFileName = decryptedFileName.Replace("ccp", ".");
                        }


                        if (!System.IO.Directory.Exists(Path.GetTempPath() + "cryptor"))
                        {
                            System.IO.Directory.CreateDirectory(System.IO.Path.GetTempPath() + "cryptor");
                        }

                        string temp_path = Path.GetTempPath() + "cryptor" + "\\";
                        try
                        {
                            enc.Decrypt(fileToDecrypt, temp_path + decryptedFileName);
                            nofilesdecrypted++;
                        }
                        catch (Exception ex)
                        {
                            continue;
                        }
                    }



                    if (nofilesdecrypted != 0)
                    {
                        VirtualDriveCreator.MapDrive('X', Path.GetTempPath() + "cryptor");
                        MessageBox.Show("Files with matching usb and pasword were decryped successfully.");
                        writeLog("SUCCESSFUL", nofilesdecrypted);
                    }

                    else
                    {
                        MessageBox.Show("No files decrypted as didn't match the original usb and pasword.");
                        writeLog("UNSUCCESSFUL", nofilesdecrypted);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }