Recently, I am working on a winform project. Because I am using the client to directly connect to the database, I need to deploy the app on the client. config. Because Enterprise Library is used. the connectionstrings In the config file are encrypted and searched for msdn, and a ready-made tool is available. ASP. net iis registration tool (aspnet_regiis.exe), but it can only be used for ASP. NET web. config files. Is there any way we can do it? Of course, the answer is no.
Configuration Options
-PDFSection webapplicationdirectory |
Decrypts the specified configuration section of the web. config file in the specified physical (non-virtual) directory. |
-WordpressSection webapplicationdirectory |
Encrypts the specified configuration section of the web. config file in the specified physical (non-virtual) directory. |
-The PDF and-Ave parameters are for the web in the specified physical directory. the config file is encrypted. the config file is renamed as web. through these two parameters, you can "cheat" the system to encrypt the specified configuration section. We only need to change the encrypted file name back to the app. config:
Step 1: First rename app. config in the directory to Web. config.
Step 2: Open the SDK command prompt and enter the command: aspnet_regiis-Arg "configuration section" "directory". Take my project as an example. The contents of the pre-encryption config file are as follows:
1 <? XML version = "1.0" encoding = "UTF-8" ?>
2 < Configuration >
3 < Configsections >
4 < Section Name = "Dataconfiguration" Type = "Microsoft. Practices. enterpriselibrary. Data. configuration. databasesettings, Microsoft. Practices. enterpriselibrary. Data, version = 2.0.0.0, culture = neutral, publickeytoken = NULL" />
5 </ Configsections >
6 < Dataconfiguration Defaultdatabase = "Connection string" />
7 < Connectionstrings >
8 < Add Name = "Connection string" Connectionstring = "Database = locomotivestat; server = 10.167.61.49; user id = sa; Password = sa ;"
9 Providername = "System. Data. sqlclient" />
10 </ Connectionstrings >
11 </ Configuration >
Run the following command: aspnet_regiis-VF "connectionstrings" "E: \ Development Directory". The encrypted config file is as follows:
1 <? XML version = "1.0" encoding = "UTF-8" ?>
2 < Configuration >
3 < Configsections >
4 < Section Name = "Dataconfiguration" Type = "Microsoft. Practices. enterpriselibrary. Data. configuration. databasesettings, Microsoft. Practices. enterpriselibrary. Data, version = 2.0.0.0, culture = neutral, publickeytoken = NULL" />
5 </ Configsections >
6 < Dataconfiguration Defaultdatabase = "Connection string" />
7 < Connectionstrings Configprotectionprovider = "Rsaprotectedconfigurationprovider" >
8 < Encrypteddata Type = "Http://www.w3.org/2001/04/xmlenc#Element"
9 Xmlns = "Http://www.w3.org/2001/04/xmlenc" >
10 < Encryptionmethod Algorithm = "Http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
11 < Keyinfo Xmlns = "Http://www.w3.org/2000/09/xmldsig" >
12 < Encryptedkey Xmlns = "Http://www.w3.org/2001/04/xmlenc" >
13 < Encryptionmethod Algorithm = "Http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
14 < Keyinfo Xmlns = "Http://www.w3.org/2000/09/xmldsig" >
15 < Keyname > RSA key </ Keyname >
16 </ Keyinfo >
17 < Cipherdata >
18 < Ciphervalue > Authorization/7dqcd1u9glqfei/authorization/yw7g8xlrco0h2 + yyd/tqtnovmu/rkdjmsjzmnwpwq + s2vewk4u1_jqwlcfbr/authorization = </ Ciphervalue >
19 </ Cipherdata >
20 </ Encryptedkey >
21 </ Keyinfo >
22 < Cipherdata >
23 < Ciphervalue > Blwv/examples/rdcg + wiz7tl5d/examples + pxcw4oe1w/examples + fscs2w/examples + w9mxtvdmo/qszxfxloemis/examples + r66 + l2c0xvehbt9ssg </ Ciphervalue >
24 </ Cipherdata >
25 </ Encrypteddata >
26 </ Connectionstrings >
27 </ Configuration >
We have completed the task. Now we only need to change the Web. config file name back to app. config.ProgramYou do not need to decrypt the file in the project ,. net Framework will automatically complete for us. If you want to decrypt the file, it is also very easy, enter aspnet_regiis-PDF "configuration section" "directory" in the SDK command prompt.
Reproduced to: http://www.cnblogs.com/jinjian/archive/2006/09/06/496009.html