具体的可以参考petshop源码程序。
加密前:
<connectionStrings> <add name="SQLProfileConnString" connectionString="server=(local);user id=mspetshop;password=pass@word1;database=MSPetShop4Profile;min pool size=4;max pool size=4;packet size=3072" providerName="System.Data.SqlClient" /> <add name="SQLMembershipConnString" connectionString="server=(local);user id=mspetshop;password=pass@word1;database=MSPetShop4Services;min pool size=4;max pool size=4;packet size=3072" providerName="System.Data.SqlClient" /> <add name="SQLConnString1" connectionString="server=(local);user id=mspetshop;password=pass@word1;database=MSPetShop4;min pool size=4;max pool size=4;packet size=3072" providerName="System.Data.SqlClient" /> <add name="SQLConnString2" connectionString="server=(local);user id=mspetshop;password=pass@word1;database=MSPetShop4;min pool size=4;max pool size=4;packet size=1024" providerName="System.Data.SqlClient" /> <add name="SQLConnString3" connectionString="server=(local);user id=mspetshop;password=pass@word1;database=MSPetShop4Orders;min pool size=4;max pool size=4;packet size=1024" providerName="System.Data.SqlClient" /> <add name="OraProfileConnString" connectionString="Data Source=localhost;user id=MSPETSHOPPROFILE;password=pass@word1;min pool size=4;max pool size=4" providerName="System.Data.OracleClient" /> <add name="OraMembershipConnString" connectionString="Data Source=localhost;user id=MSPETSHOPMEMBERSHIP;password=pass@word1;min pool size=4;max pool size=4" providerName="System.Data.OracleClient" /> <add name="OraConnString1" connectionString="Data Source=localhost;user id=MSPETSHOP;password=pass@word1;min pool size=4;max pool size=4" providerName="System.Data.OracleClient" /> <add name="OraConnString2" connectionString="Data Source=localhost;user id=MSPETSHOP;password=pass@word1;min pool size=4;max pool size=4" providerName="System.Data.OracleClient" /> <add name="OraConnString3" connectionString="Data Source=localhost;user id=MSPETSHOPORDERS;password=pass@word1;min pool size=4;max pool size=4" providerName="System.Data.OracleClient" /> </connectionStrings>
加密后:
<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>toBlOJmJmZ/3SYJaltdhQA/RfrSAwf633228VBzG0ZUeTq2jsJksoxQID0GVozH3AQbfbIVoXdg0KsPgLpT3a+Xi5KGvWwyurrNqt0cPBCvWoBRtQLoc5ni87hbqDFaxSTrS9xX2kIpeC91QE1lA+l7Kk9e48YaJxPw82ZnzgUM=</CipherValue> </CipherData> </EncryptedKey> </KeyInfo> <CipherData> <CipherValue>yFoUrcd3MH3tsgquIezF6sfaI2rZKlxYDRX58m0jdgKTNK1hpwItSbcPbqioyHu251OKH38kI0IBUNE1VMr6vBqGEmnZyZjI77ZBkJWg6wNjW84Ul2TuyM0uQodpUabC+7v4vKtzrVMQ6Og3gShqsg8XEQqCZ+R5fS8xFNDlVhxEL1PmexiYuamc4Gple8RdnVnGyqWRsAxuphu00zGmQxuD6ZCUnk2riBYb7XVHM5jzX42u4a1gYG581HQwFCPDl2hP2+grfFKt+DJc23o0ceARY02bJJ0Z0wX1Cn2TIx/WK1vFqKgxE0/s9sd8rg+EOdpaXLWYG3QWhlA/LgIKgSvcevCLPX+N+p1i/RYVOEanlNAca8tvQazXWGdabDc+tl6XdViKMwgUJntnMEm1+C5xQEo4V+ImqYwSMyUqqUGrMWQQeYe9kLVFGXdTO+fizMRX1IVenCKykOE3SZHHw0BMlUBVpXw64cq/zlADa/NigcEOaKa/xjku7AdwkR2PNAInblzxnJBxUPtQGTboZVQ3yBnqyMY48uwOo/T3/rHQFW7P3DkIyutAZxBxQ4Zcko2qf/25OWjGsIQpXcXF6XkJSkNN8fzgySsYY2SnsTSlqPPyKRrb8OEEQ5YxZ+FdAHKesEowrOF+QmZh177rD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gZ6C+C8=</CipherValue> </CipherData> </EncryptedData> </connectionStrings>
EncryptWebConfig.bat加密批处理代码:
@echo off C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -pef "connectionStrings" "D:\Program Files\Microsoft\.NET Pet Shop 4.0\Web" PAUSE
DecryptWebConfig.bat解密批处理代码:
@echo off C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -pdf "connectionStrings" "D:\Program Files\Microsoft\.NET Pet Shop 4.0\Web" PAUSE
直接将语句拷贝到.BAT文件中,D:\Program Files\Microsoft\.NET Pet Shop 4.0\Web 为相应的web.config所在的路径,只能在一台电脑上操作,否则不可逆!