asp.net uses encrypted database join strings to ensure data security
- 2021-01-11 01:57:32
- OfStack
When we publish the website, encrypt web.config, which can effectively ensure the database user and password security, the steps are as follows:
1. Add a key
Execution :C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\ aspnet_regiis-pc "hnlaw" -exp
Where "hnlaw" is the key name
2. Add web.config node
In web. config < configuration > < /configuration > Add between:
<configProtectedData>
<providers>
<add keyContainerName="hnlaw" useMachineContainer="true" description="Uses RsaCryptoServiceProvider to encrypt and
decrypt" name="hnlaw" type="System.Configuration.RsaProtectedConfigurationProvider,System.Configuration, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</configProtectedData>
Note: Here, keyContainerName="hnlaw" and name="hnlaw" represent the name of your key respectively;
3. Encryption web. config
Add a batch file enweb. bat to the root directory of the website. The contents are as follows:
@echo off
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "E:\HS Studio\Donet2\Hnlawyer" -prov
"hnlaw"
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis -pef "connectionStrings" "E:\HS Studio\Donet2\Hnlawyer" -prov
"hnlaw"
PAUSE
Register the path and name above!
Success appears after running!
4. The decryption
Also add a batch file deweb. bat to the root directory of the website. The contents are as follows:
@echo off
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis -pef "system.web/identity" "E:\HS Studio\Donet2\Hnlawyer"
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis -pdf "connectionStrings" "E:\HS Studio\Donet2\Hnlawyer"
PAUSE
C: Documents and Settings All Users Application Data Microsoft Crypto RSA MachineKeys: Documents and Settings Application Data Microsoft Crypto RSA MachineKeys
Error message from the provider: The RSA key container could: The RSA key container could: Error message from the provider: The RSA key container could
not be opened.
Unable to read
This may occur, if you do not have your own server, do not have permission to modify the MachineKeys directory, do not know there are other solutions, hope everyone to share 1 :)