Encrypt the winform app. config file
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. the ready-made tool ASP is found. net IIS registration tool (aspnet_regiis.exe), but it can only be used for ASP. net web. config file, is there no way for us? Of course, the answer is no.
Configuration Options
-PDF section webapplicationdirectory |
Decrypts the specified configuration section of the web. config file in the specified physical (non-virtual) directory. |
-Wordpress section 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> encrypt/7dqcd1u9glqfei/encrypt/yw7g8xlrco0h2 + yyd/tqtnovmu/rkdjmsjzmnwpwq + encrypt/decrypt = </ciphervalue>
19 </cipherdata>
20 </encryptedkey>
21 </keyinfo>
22 <cipherdata>
23 <ciphervalue> blwv/strong/rdcg + wiz7tl5d/strong + pxcw4oe1w/strong + fscs2w/strong + w9mxtvdmo/qszxfxloemis/strong + r66 + strong </ciphervalue>
24 </cipherdata>
25 </encrypteddata>
26 </connectionstrings>
27 </configuration>
as you can see, we have completed the task. Now we only need. change the config file name back to the app. in the Program project, you do not need to decrypt the file ,. 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.