问题描述
我有一个app.config文件,需要与我的应用程序一起分发。由于创建了对我添加的ASMX Web服务的服务引用而创建了它。
I have an app.config file that I need to distribute with my application. It was created because of a Service Reference to an ASMX web service I added.
如果修改/查看此文件不是什么大问题,但我仍然想确保它的安全。我已经检查了配置的哈希值并确保它是有效的,但是我仍然想要添加一层保护。
It isn't a huge deal if this file is modified/viewed, but I still would like to make it secure. I already check the hash of the config and make sure it is valid, but I still want an added layer of protection.
这是我的配置:
推荐答案
您不能加密整个< system .serviceModel>
-这是一个配置节组,其中包含配置节。
You cannot encrypt the entire <system.serviceModel>
- it's a configuration section group, which contains configuration sections.
aspnet_regiis
仅加密配置部分-因此您需要有选择地加密所需的部分,例如:
The aspnet_regiis
will only encrypt configuration sections - so you need to selectively encrypt those parts you need, like this:
cd C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
aspnet_regiis.exe -pef "system.serviceModel/bindings" .
aspnet_regiis.exe -pef "system.serviceModel/services" .
等。
有了这个,您可以轻松加密您所需的内容-不太重要的内容可以保留为明文形式。
With this, you can encrypt what you need easily - what isn't too important, can be left in clear text.
警告词:由于它是 aspnet_regiis
,它希望处理的是网站.config
文件-将您的 app.config
复制到一个位置,并将其命名为 web.config
,对部分进行加密,然后将这些加密的部分复制回自己的 app.config
中。
Word of warning: since it's aspnet_regiis
, it expects to be dealing with a web.config
file - copy your app.config
to a location and call it web.config
, encrypt your sections, and copy those encrypted sections back into your own app.config
.
或编写您自己的配置部分加密器/解密器-实际上只需要几行代码!或使用我的-我写了一个小的 ConfigSectionCrypt
实用程序,将其从我的-带有完整源代码(C#-.NET 3.5-Visual Studio 2008)。它允许您从任何配置文件中加密和解密部分-只需在命令行中指定文件名即可。
Or write your own config section encrypter/decrypter - it's really just a few lines of code! Or use mine - I wrote a small ConfigSectionCrypt
utility, come grab it off my OneDrive - with full source (C# - .NET 3.5 - Visual Studio 2008). It allows you to encrypt and decrypt sections from any config file - just specify the file name on the command line.
这篇关于加密app.config文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!