Hello there,
I just found that the compiled code won't hide the string variables so
that I can see them by opening the execuable using Notepad. I have
couple applications that have password hardcoded and I've been thinking
that the string varialbes are hidden in compiled code. I knew that the
VS.NET doesn't compile the source code into machine code. But I didn't
know that it will expose string variables in the compiled code. Here is
my code:
static private string Hello1 = "Hello my world";
private void button1_Click(object sender, EventArgs e)
{
string filePath = @"C:\Windows\Notepad.exe";
string userName = "Username";
string password1 = "MyPassword";
// ProcessStartInfo psi = new ProcessStartInfo(args[0]);
ProcessStartInfo psi = new ProcessStartInfo(filePath);
psi.UserName = userName;
psi.Password = ConvertStringToSecureString(password1);
psi.Domain = "";
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(psi);
}
private static SecureString ConvertStringToSecureString(string
password)
{
SecureString tempSecureString = new SecureString();
foreach (char c in password)
{
tempSecureString.AppendChar(c);
}
return tempSecureString;
}
When I opened the compiled version using the notepad, I see this in the
middle of text:
-- snippet --
ControlCollection get_Controls Add ResumeLayout
WindowsApplication1.Properties.Resources.resources
WindowsApplication1.Form1.resources QW i n d o w s A p p l i c a t
i o n 1 . P r o p e r t i e s . R e s o u r c e s -C : \ W i n d o w s
\ N o t e p a d . e x e U s e r n a m e M y P a s s w o r d b u
t t o n 1 F o r m 1 H e l l o m y w o r l d Asě*˝???^쩾?
톧\V4?
! %
-- snippet --
Clearly, I can see the hello1, filepath, username, password values.
I am using VS.NET 2005 with Framework v2.0. And I found the RunAs code
sample from Web sites. Many sites have the examples.
I have to hardcode the password in my application in SECURE way. Could
someone give me an example or tips? I appreciate your help.