public void RSATests_String_EncryptDecrypt(string text) { using (var cryptor = new RSACrypt()) { var cryptBuffer = Encoding.UTF8.GetBytes(text); var encryptBuffer = cryptor.Encrypt(cryptBuffer); var decryptBuffer = cryptor.Decrypt(encryptBuffer); var resultString = Encoding.UTF8.GetString(decryptBuffer); Assert.AreEqual(resultString, text); } }
public void RSATests_BigString_EncryptDecrypt(string fileName) { using (var cryptor = new RSACrypt()) { var text = File.ReadAllText(fileName); var cryptBuffer = Encoding.UTF8.GetBytes(text); var encryptBuffer = cryptor.Encrypt(cryptBuffer); var decryptBuffer = cryptor.Decrypt(encryptBuffer); var resultString = Encoding.UTF8.GetString(decryptBuffer); Assert.AreEqual(resultString, text); } }
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 testbtn_Click(object sender, EventArgs e)//encrypt { string encrtypted = RSAobj.Encrypt(testbox.Text); testtextbox.Text = encrtypted; }