My custom .Net process maps a drive with a different account than the current context. The password is stored in the config file, DPAPI encrypted with the machine key.
The code works, but I'm wondering if usage of SecureString would offer additional security. I believe the weakness below lies with the PlainBytes array and the MapPwd and MapDriveCmd strings when they are in memory in plain text.
I've done some research on SecureString, but don't quite understand if it applies here. The three local suspect variables aren't used after the code below. If I keep it as is without SecureString, will the garage collector dispose of these before the process ends?
byte[] CipherBytes = Convert.FromBase64String(ConfigurationManager.AppSettings.Get("MapPwd").Trim());
byte[] PlainBytes = ProtectedData.Unprotect(CipherBytes, null, DataProtectionScope.LocalMachine);
string MapPwd = System.Text.Encoding.UTF8.GetString(PlainBytes);
string MapDriveCmd = "/C net use " + MapLetter + " " + MapPath + " " + MapPwd + " /USER:" + MapUser + " /PERSISTENT:NO";
System.Diagnostics.Process MapDrive = System.Diagnostics.Process.Start("CMD.exe", MapDriveCmd);
MapDrive.WaitForExit();
Any additional comment on the technique in general is welcome. Thanks.