Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Okay, so I have the following code:
File.WriteAllText("encrypted password.txt", RSAObj.ToXmlString(true));
in program.cs, but how can I pass the "RSAObj.ToXmlString(true) (the encrypted password) to form 1 textbox?

What I have tried:

Research and different codes, I have no idea
Posted
Updated 26-Jan-19 11:37am
v3

C#
form1.textbox1.Text = RSAObj.ToXmlString(true);

or a better idea ...
C#
String encpwd = RSAObj.ToXmlString(true);
File.WriteAllText("encrypted password.txt", encpwd);
form1.textbox1.Text = encpwd;
 
Share this answer
 
Comments
Member 14130699 26-Jan-19 13:27pm    
I get two errors: 'Form1.Form1.textBox1' is inaccessible due to its protection level and An object reference is required for the non-static field, method, or property 'Form1.Form1.textBox1'

Please help?
Richard MacCutchan 27-Jan-19 3:34am    
Don't try to use static references to your form. And check the protection level of the textbox, it should not be private if you want to do this. Alternatively create a method in Form1 that can set the text.
You can't do it directly. The best way to do this is to create a public function in Form1. Something like:

public void RSAObj(string value) 
{
   textbox1.text = value;
}


Then, in program.cs do something like this:

C#
static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Form1 form1 = new Form1();
            form1.RSAObj(RSAObj.ToXmlString(true));
            Application.Run(form1);
        }


- Pete
 
Share this answer
 
Comments
Member 14130699 27-Jan-19 6:38am    
Hi, your code works, but when I change "(RSAObj.ToXmlString(true)); to
(RSAObj.Encrypt(myKey, false)); I get an error. Why?
Member 14130699 27-Jan-19 7:10am    
Hey man, these are the errors I get : Argument 1: cannot convert from 'byte[] to string' and The best overloaded method match for Form1.RSAObj(string)' has some invalid arguments.

You're very helpful.
Member 14130699 27-Jan-19 7:12am    
I also use this code: Byte[] myKey = AES.generateKey();
pdoxtader 27-Jan-19 9:59am    
The problem is that the function I provided accepts a string, and the new function you are trying to use returns Byte[]. You need to set up a new function that accepts Byte[], and write code in it to handle the byte array.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900