private void button1_Click(object sender, EventArgs e) { if (listBox1.SelectedIndex >= 0) { int index = listBox1.SelectedIndex; //kendi arkadaslarına eklemesi char[] charsToTrim = { ' ', '"' }; string friendPublic = friendRequests[index, 1].Trim(charsToTrim); string friendMail = friendRequests[index, 0].Trim(charsToTrim); string friendUsername = friendRequests[index, 2].Trim(charsToTrim); //Creating AES KEY int length = 32; // creating a StringBuilder object() StringBuilder str_build = new StringBuilder(); Random random = new Random(); char letter; for (int i = 0; i < length; i++) { double flt = random.NextDouble(); int shift = Convert.ToInt32(Math.Floor(25 * flt)); letter = Convert.ToChar(shift + 65); str_build.Append(letter); } string aesKey = str_build.ToString(); //ENCRYPT AES KEY WITH MY PUBLIC TO STORE IN DB string encrtyptedAes = RSAobj.Encrypt(aesKey); var friend = new { friendUsername = friendUsername, mail = friendMail, publicKey = friendPublic, aes = encrtyptedAes }; try { FriendReqClient.Set(EncryptedMailApp.LoginForm.user + "/friends/" + friendUsername, friend); FriendReqClient.Delete(EncryptedMailApp.LoginForm.user + "/friendRequests/" + friendUsername); } catch { MessageBox.Show("There is an error occured!"); } //karşı tarafa ekleme encrtyptedAes = RSAobj.EncryptFriend(aesKey, friend.publicKey); friend = new { friendUsername = EncryptedMailApp.LoginForm.user, mail = EncryptedMailApp.LoginForm.mail, publicKey = EncryptedMailApp.LoginForm.userpublicKey.Replace("\r", "").Replace("\n", ""), aes = encrtyptedAes }; try { FriendReqClient.Set(friendUsername + "/friends/" + EncryptedMailApp.LoginForm.user, friend); } catch { MessageBox.Show("There is an error occured!"); } } else { MessageBox.Show("There is no selected request!"); } }
private void button15_Click(object sender, EventArgs e) { testtextbox.Text = RSAobj.EncryptFriend(testbox.Text, keybox.Text); }