This is my code in program.cs:
static void Main(string[] arg)
{
Boolean bCreatedNew;
Mutex m = new Mutex(false, "schoolProject", out bCreatedNew);
m.WaitOne();
GC.Collect();
if (!bCreatedNew) return;
m.ReleaseMutex();
System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Highest;
Byte[] myKey = AES.generateKey();
string result = System.Text.Encoding.UTF8.GetString(myKey);
RSACryptoServiceProvider RSAObj = new RSACryptoServiceProvider();
File.WriteAllText("rsa.txt", RSAObj.ToXmlString(true));
File.WriteAllBytes("aes.txt", RSAObj.Encrypt(myKey, false));
encryptAll(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), myKey);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 form1 = new Form1();
form1.RSAObj(result);
Application.Run(form1);
}
}
}
And this is my code in form 1:
public void RSAObj(string value)
{
textBox1.Text = value;
}
As you can see, this program makes two text documents, one with RSA and another with AES key which is encrypted by RSA, and it sends the AES key to a textbox in form 1. The problem is that I don't get the AES key in the textbox, but random rubbish, for example: "6˞Ea���X�)Xl�F". Why? As you can see I have converted bytes to string to send the AES key to form 1 textbox:
Byte[] myKey = AES.generateKey();
string result = System.Text.Encoding.UTF8.GetString(myKey);
I tried making the program send the RSA key to a textbox in form 1, and that worked by changing:
form1.RSAObj(result);
to
form1.RSAObj(RSAObj.ToXmlString(true));
How can I make it send the AES key though?
What I have tried: