使用IISWASOnlyAesProvider生成加密的IIS应用程序池标识密码

6

我希望能够使用IIS中使用的算法生成加密密码。

加密后的值在applicationHost.config文件中如下所示:

<applicationPools> 
    <add name="MyAppPool"> 
        <processModel identityType="SpecificUser" userName="TestUser" 
password="[enc:IISWASOnlyAesProvider:N8mr4dLU6PnMW5xlmCWg6914cKePgeU0fTbxew 
ZppiwyTLmBQh0mZnFywQO78pQY:enc]" /> 
    </add> 
</applicationPools>

参考: http://technet.microsoft.com/en-us/library/dd163536.aspx

我看到机器密钥存储在这里:

C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys

参考链接:http://www.asprangers.com/post/2012/05/03/MachineKeys-on-IIS-7x-Inside-Out.aspx

我想用c#编写一些代码来完成这个任务,但我不是密码学专家... 我能否使用下面被接受的SO答案中的代码,使用来自机器密钥的明文密码和密钥生成如上所示的加密密码呢?

使用C#进行AES加密

1个回答

0
为什么你要尝试生成一个像IIS一样的东西,是为了将其存储在IIS配置中吗?如果是这样,配置API应该会自动为您完成,您可以使用Microsoft.Web.Administration.ServerManager来实现,例如:
    using(ServerManager serverManager = new ServerManager()) { 
        Configuration config = serverManager.GetApplicationHostConfiguration();

        ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites");

        ConfigurationElement virtualDirectoryDefaultsElement = sitesSection.GetChildElement("virtualDirectoryDefaults");
        virtualDirectoryDefaultsElement["password"] = @"asd";

        serverManager.CommitChanges();
    }

1
谢谢,是的,我知道我可以使用API进行设置。原因是我们正在使用puppet来管理ApplicationHost.config作为模板文件。我们还使用puppet管理密码,因此puppet需要能够创建哈希以用作模板中加密密码字符串的变量,以便它知道是否更新实际文件。 - Andy Arismendi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接