1. Open notepad and copy the following code to a new file.
Copy codeThe Code is as follows: <% @ Page Language = "C #" %>
<%
Response. Write (System. Security. Principal. WindowsIdentity. GetCurrent (). Name );
%>
Save my. aspx to your web directory and run the form to display "nt authority \ network service ". Successful!
2. (key step) Run cmd and execute the following
Aspnet_regiis-pa "NetFrameworkConfigurationKey" "nt authority \ network service"
Note: register the RSA key container of the default RsaProtectedConfigurationProvider,
NetFrameworkConfigurationKey is the default provider of RsaProtectedConfigurationProvider. Successful!
3. Now, you can encrypt web. config and run:
Encryption: aspnet_regiis-pe "connectionStrings"-app "/Myweb"
Note: "connectionStrings" is the section to be encrypted. "/Myweb" is the web directory.
Decryption: aspnet_regiis-pd "connectionStrings"-app "/Myweb"
Successful!
4. This can be called in the Program (no decryption is required, haha
):
...
String connstr = ConfigurationManager. ConnectionStrings ["myConnstr"]. ConnectionString. ToString ();
...
You can also create your own RSA key container as follows:
(1) create a "MyKeys" key container and run: aspnet_regiis-pc "MyKeys"-exp
(2) Add the following to web. config:
Copy codeThe Code is as follows: <protectedData>
<Providers>
<Add name = "MyProvider"
Type = "System. Configuration. RsaProtectedConfigurationProvider, System. Configuration, Version = 2.0. 0.0,
Culture = neutral, PublicKeyToken = b03f5f7f11d0a3a,
ProcessorArchitecture = MSIL"
KeyContainerName = "MyKeys"
UseMachineContainer = "true"/>
</Providers>
</ProtectedData>
Save.
(3) authorize the account to access the computer-level "MyKeys" RSA key container and run:
Aspnet_regiis-pa "MyKeys" "nt authority \ network service"
(4) Now, you can encrypt web. config and run:
Encryption: aspnet_regiis-pe "connectionStrings"-app "/Myweb"-prov "MyProvider"
Note: "connectionStrings" is the section to be encrypted, "/Myweb" is the web directory, and "MyProvider" is the private key container.
Decryption: aspnet_regiis-pd "connectionStrings"-app "/Myweb"-prov "MyProvider"