我的自定义 .Net 进程使用与当前上下文不同的帐户映射驱动器。密码存储在配置文件中,DPAPI 使用机器密钥加密。
该代码有效,但我想知道 SecureString 的使用是否会提供额外的安全性。我相信下面的弱点在于 PlainBytes 数组和 MapPwd 和 MapDriveCmd 字符串,当它们以纯文本形式存在于内存中时。
我对 SecureString 进行了一些研究,但不太了解它是否适用于此。在下面的代码之后没有使用三个局部可疑变量。如果我在没有 SecureString 的情况下保持原样,车库收集器会在流程结束之前处理掉这些吗?
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();
欢迎对该技术的任何其他评论。谢谢。