1

我正在使用 DPAPIProtectData如下:

var temp = new byte[32]
{
    1,1,1,1,1,1,1,1,
    2,2,2,2,2,2,2,3,
    3,3,3,3,3,3,3,3,
    4,4,4,4,4,4,4,4
};

ProtectedData.Protect(temp, null, DataProtectionScope.CurrentUser);
string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

让我们假设现在 temp 看起来像:

temp = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,....31 };

我想从 .exe 文件以及我的 WebService (IIS) 执行此代码。
问题是,如果我从 exe 运行代码,则当前用户是MyDomain/Administrator,如果我从 WebService 运行代码,则当前用户是IIS APPPOOL/MyApp.

我该如何解决这个问题?我正在尝试从WebService.exe 文件运行,如下所示:

Process.Start(@"C:\myexe.exe");

但是由于某种原因它不起作用(我可以完全访问我的 iis 应用程序),无论如何我认为这不是这种情况下的正确解决方案。

注意:出于安全原因,我无法从更改DataProtectionScope.LocalMachineDataProtectionScope.CurrentUser

4

2 回答 2

3

如果你不想使用,你可以从一开始DataProtectionScope.CurrentUser就安装它。LocalMachine然后,将其解密WebService,然后使用. 确保删除旧值及其所有临时副本。通过这种方式,您可以在适当的用户运行时将其从其中取出并锁定。CurrentUserLocalMachine

这仍然使密钥在LocalMachine水平面上暴露,但时间窗口更短。

另一种解决方案是使用LocalMachine和使用额外的熵特征,并在两个可执行文件之间共享一个秘密。这可能是应用程序已知的模糊值(没有“真正的”安全性),也可能是用户提供的密码。用户提供的密码解决方案可能更安全,但也更痛苦和更多的编程开销。

如果安装和运行之间的时间窗口WebService很小,第一个解决方案可能很合适。

于 2016-08-31T14:50:00.870 回答
0

The problem was solved.
I running the IIS application from local user.
You can find this by selecting the app pool and clicking Advance Settings... under the Actions pane menu. Select Identity and then click the button beside the current user listed. Select Custom account and click Set. Use the format domain\username for the username and enter the password for the user.

于 2016-09-07T09:50:55.163 回答