示例#1
0
        private void importRsaKeys_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(_userId))
            {
                MessageBox.Show("Please authorize your Google account!", "Drive Crypt", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            ofd.Filter           = "Drive Crypt user keys (*" + UserCryptor.PRIV_KEY_EXTENSION + ")|*" + UserCryptor.PRIV_KEY_EXTENSION;
            ofd.FilterIndex      = 1;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if (_userCryptor == null)
                    {
                        _userCryptor = new UserCryptor(_userId);
                    }
                    _userCryptor.ImportKeys(ofd.FileName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Could not import user keys!\nReason: " + ex.Message, "Drive Crypt", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
示例#2
0
        private void changePassword_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(_userId))
            {
                MessageBox.Show("Please authorize your Google account!", "Drive Crypt", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (newPassword.Text.Equals(confirmNewPassword.Text))
            {
                try
                {
                    _userCryptor = new UserCryptor(_userId);
                    _userCryptor.LoadKeys(password.Text);
                    _userCryptor.SaveKeys(newPassword.Text, true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Could not change password! Incorrect master password?\nReason: " + ex.Message, "Drive Crypt", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Passwords don't match!", "Drive Crypt", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
示例#3
0
        private void exportRsaKeys_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(_userId))
            {
                MessageBox.Show("Please authorize your Google account!", "Drive Crypt", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            FolderBrowserDialog fbd = new FolderBrowserDialog();

            if (fbd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if (_userCryptor == null)
                    {
                        _userCryptor = new UserCryptor(_userId);
                    }
                    _userCryptor.ExportKeys(fbd.SelectedPath);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Could not export user keys!\nReason: " + ex.Message, "Drive Crypt", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
示例#4
0
        private void register_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(_userId))
            {
                MessageBox.Show("Please authorize your Google account!", "Drive Crypt", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (password.Text.Equals(confirmPassword.Text))
            {
                try
                {
                    _userCryptor = new UserCryptor(_userId);
                    _userCryptor.CreateKeys(password.Text);
                    var mainForm = new Form1(this);
                    Hide();
                    mainForm.Show();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Could not create new user keys!\nReason: " + ex.Message, "Drive Crypt", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Passwords don't match!", "Drive Crypt", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
示例#5
0
        private void SharePublicKey(string emailToShare)
        {
            var publicKeyPath = UserCryptor.GetPublicKeyPath(_authorizationForm._userId);

            if (!File.Exists(publicKeyPath))
            {
                _authorizationForm._userCryptor.SavePublicKey();
            }

            GDriveManager.ShareFile(publicKeyPath, emailToShare, _authorizationForm._userInfo.Name);
        }
示例#6
0
        private void login_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(_userId))
            {
                MessageBox.Show("Please authorize your Google account!", "Drive Crypt", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            try
            {
                _userCryptor = new UserCryptor(_userId);
                _userCryptor.LoadKeys(password.Text);
                var mainForm = new Form1(this);
                Hide();
                mainForm.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not load user keys! Incorrect master password?\nReason: " + ex.Message, "Drive Crypt", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#7
0
        private void share_Click(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog();

            ofd.InitialDirectory = _directoryPath;
            ofd.Filter           = "All Files(*.*) | *.*";
            ofd.FilterIndex      = 1;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                var emailToShare = emailInput.Text;
                if (!IsValidEmail(emailToShare))
                {
                    MessageBox.Show("Invalid email address!", "Drive Crypt", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                GDriveManager.ShareFile(ofd.FileName, emailToShare, _authorizationForm._userInfo.Name);

                var userId          = Base64Utils.EncodeBase64(emailToShare);
                var shareKeyCryptor = new UserCryptor(userId);

                var keyFilePath = GetUserKeysFolder() + Path.DirectorySeparatorChar + userId + UserCryptor.PUB_KEY_EXTENSION;
                if (File.Exists(keyFilePath))
                {
                    shareKeyCryptor.LoadPublicKey(keyFilePath);
                }
                else
                {
                    MessageBox.Show("The requested user did not share his keys with you yet!", "Drive Crypt", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                var keyFilename            = FileCryptor.PrepareKeyForSharing(ofd.FileName, _authorizationForm._userCryptor, shareKeyCryptor);
                var keyFilenameWithoutPath = Path.GetFileName(keyFilename);
                GDriveManager.UploadFile(keyFilename, keyFilenameWithoutPath);
                GDriveManager.ShareFile(keyFilename, emailToShare, _authorizationForm._userInfo.Name);
            }
        }
示例#8
0
        private void shareToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (FolderList.SelectedNode != null)
            {
                TreeNode SelectedNode = FolderList.SelectedNode;
                string   FilePath     = SelectedNode.Tag.ToString();

                var emailToShare = emailInput.Text;
                if (!IsValidEmail(emailToShare))
                {
                    MessageBox.Show("Invalid email address!", "Drive Crypt", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                GDriveManager.ShareFile(FilePath, emailToShare, _authorizationForm._userInfo.Name);

                var userId          = Base64Utils.EncodeBase64(emailToShare);
                var shareKeyCryptor = new UserCryptor(userId);

                var keyFilePath = GetUserKeysFolder() + Path.DirectorySeparatorChar + userId + UserCryptor.PUB_KEY_EXTENSION;
                if (File.Exists(keyFilePath))
                {
                    shareKeyCryptor.LoadPublicKey(keyFilePath);
                }
                else
                {
                    MessageBox.Show("The requested user did not share his keys with you yet!", "Drive Crypt", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                var keyFilename            = FileCryptor.PrepareKeyForSharing(FilePath, _authorizationForm._userCryptor, shareKeyCryptor);
                var keyFilenameWithoutPath = Path.GetFileName(keyFilename);
                GDriveManager.UploadFile(keyFilename, keyFilenameWithoutPath);
                GDriveManager.ShareFile(keyFilename, emailToShare, _authorizationForm._userInfo.Name);
            }
        }