数据库连接字符串加密解密
一、加密:
明文如下:
<connectionStrings> <add name="SQLProfileConnString" connectionString="server=.;database=MSPetShop4Profile;user id=mspetshop;password=pass@word1;min pool size=4;max pool size=4;" providerName="System.Data.SqlClient" /> <add name="SQLMembershipConnString" connectionString="server=.;database=MSPetShop4Services;user id=mspetshop;password=pass@word1;min pool size=4;max pool size=4;" providerName="System.Data.SqlClient" /> <add name="SQLConnString1" connectionString="server=.;database=MSPetShop4;user id=mspetshop;password=pass@word1;min pool size=4;max pool size=4;" providerName="System.Data.SqlClient" /> <add name="SQLConnString2" connectionString="server=.;database=MSPetShop4;user id=mspetshop;password=pass@word1;max pool size=4;min pool size=4;" providerName="System.Data.SqlClient" /> <add name="SQLConnString3" connectionString="server=.;database=MSPetShop4Orders;user id=mspetshop;password=pass@word1;min pool size=4;max pool size=4;" providerName="System.Data.SqlClient" /> <add name="OraProfileConnString" connectionString="" providerName="System.Data.OracleClient" /> <add name="OraMembershipConnString" connectionString="" providerName="System.Data.OracleClient" /> <add name="OraConnString1" connectionString="" providerName="System.Data.OracleClient" /> <add name="OraConnString2" connectionString="" providerName="System.Data.OracleClient" /> <add name="OraConnString3" connectionString="" providerName="System.Data.OracleClient" /> </connectionStrings>
操作命令:打开SDK命令提示 , aspnet_regiis -pef "connectionStrings" d:\web 回车 //d:\web 为web.config的所在目录
加密后:
<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>t6Cms0y8Kh/t9SMwzwDsA3lVLzZZapOvRRy1iEt9YVUNRC0s49v5m4xz46SHmYqe0F9r2NIoRkrU84HgbKP+RZWEXej4ljG0vgNu0QY59mbU1ui/U+JXTNXujGlv22Am1NsJz83Od4eJVMHtvwdobCc1oG4AUq1NTmOIuI8YWFc=</CipherValue> </CipherData> </EncryptedKey> </KeyInfo> <CipherData> <CipherValue>9AxWb33S36LspJJcLGE2Evb6oyasR3i1uoeOHCt9WPPaxXkogMclgXCt+u/LCrPsj7ApBQDi2V9rKycHh2aFUsbf0Trwuq+MS8eFShIzU5/RTAmJjMj0tWwTYYmZt0A7R3bA18uj0Kyb/aoK1ozW1Qu60WtKYpwjHbTRDjkHz/lEc/qej4IysbI2YjCSmF3NWghopssyx/5bUDc0ulvloq4bEic6JGPWI3e6MszZLLWgJRXkb0KMkjttMRr4+5eRCzWf9tAKSpNc5lOoPir1P1EcVHtGbkONH+5/KpsJncNwtjlOvRzIiJZaMjCG41QDqus6XGa73CIyrE09gO5bKqTdpstiexi5/TAwiQ3cC6lIcm6I1sSCWt//CkySiSA6DDknbhQirfKEbnRcrA+PScOLoOOSMwYI+pMzfdrdwwS1txIE84ZcixzJjMIpxSFzpnOC05CQmgohwIU/6p4avVu8i3pCpxPsh3Ayz+qJ7ZqW1TemymMBZI40ZF6EN3GPltE0iIGc10Rf6wCaVfG97WU/VezSL7oEwf9NFrqRs5JDqW2DhzvA3nLnlVIf7AY4KhzJZCrmW26xj90TGp3WEjzPkzUQitkeVtnpRKvd58NkS3T7ntgoIaddwxRcLft5WXRWqg3dlS6B74lr414JULkzh7omUCUZVtZbzBIX/bh8m8eGFWeU1zKL4c2QhZFvIRBBxl7IRziHqnG+X3QAs4AVAJLOcMm949Z8sWjPC8+jgaO00VXxNBsHcvHFlRw9M1j5/wk5mh1xZJtlpbG1nq7eWsHFfzqhdR3cjRupdgHdml/sexl9BjP1ABZd4a5jCJx7zL3aClnWCpwyocGKAyvBk8hzzHHBaX3/DtANU7iyf9h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TUEFFPjwcs7efXy+s3xefkm090pVC+la2+QHEJrSh5lUbCYJcOVnMtVDH2SwqyZZa/V0kSQ9Jlr5SYdc7kB</CipherValue> </CipherData> </EncryptedData> </connectionStrings>
二、解密方法:
操作命令:打开SDK命令提示 , aspnet_regiis -pdf "connectionStrings" d:\web 回车 //d:\web 为web.config的所在目录