winform 配置文件的加密解密

winform 配置文件的加密解密
Visual Studio 命令提示(2010) 窗口下直接输入 :
解密
aspnet_regiis -pdf connectionStrings 程序文件夹全目录


加密
aspnet_regiis -pef connectionStrings 程序文件夹全目录

注意:加密解密过程中必须把配置文件名称改为web.config
程序运行一定要改回来App.cong

也可以通过运行CMD切换到命令提示符下,进入到C:WINDOWSMicrosoft.netFrameworkv2.0.xxxx下,
其中 xxxx 是你所用的Framework版本,可以通过打开上述目录得到。
=================================================


配置文件:加密前
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="str1" connectionString="data source=127.0.0.1;database=CustomerServiceDB;
uid=sa;pwd=123" />
</connectionStrings>
</configuration>
===================================
配置文件:加密后
===================================

   
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider">
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<KeyName>Rsa Key</KeyName>
</KeyInfo>
<CipherData>

<CipherValue>UqupaYVDA7WOWEWwG1foftuhquDgLMkmgGQbDGceawbDOQzjdRQzRU9/tyr1GT0qHnAP5tAm/2PO1SaFQ
EHva6a3yVUaDdHjXYdpNx5YiI0O5sXssWZCRE7kwFPHKoK6RsIMEqjgVDFEkWFhwgjDUsIiL1TURpMcCL6HfPtP
+ns=</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>w9cu5AenHpo4oAVZYogic3CY9nQDFkutN4OAxYnmP/iBFfwdqBBJav/h7pGUrN+
+gWjT9t9IBkTWlLKd0/mEB2IIdmuvwEDLywxNZvPacbyzRI1tLlKf6oD0VLkkEqxgHD6Vh+AaM
+zypwKttzKRrAIt6uxxOzinz7cLWXEZwYfmX+ZZ7+ob8hbh0rW0Ehn2bq4DjhysROW98DPublmnJw==</CipherValue>
</CipherData>
</EncryptedData>
</connectionStrings>
</configuration>
====================================================================================

转载 请注明原文地址并标明转载:http://www.cnblogs.com/laopo 商业用途请与我联系:lcfhn168@163.com
原文地址:https://www.cnblogs.com/laopo/p/4123397.html