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); }
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); } }
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); } }