Exemplo n.º 1
0
        private void button4_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 filenameWithoutPath = Path.GetFileName(ofd.FileName);

                var file = GDriveManager.UploadFile(ofd.FileName, filenameWithoutPath);
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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);
            }
        }