这个样例代码并没有被加密,并且它不会被发布到服务器上。因为处于安全考虑,发布到服务器的<machineKey>的加密是非常重要的。你可以在清单2中看到加密后的<machineKey>。
清单 2: web.config 中加密后的machineKey
<machineKeyconfigProtectionProvider="RsaProtectedConfigurationProvider"> <EncryptedDataType="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#"> <EncryptionMethodAlgorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" /> <KeyInfoxmlns="http://www.w3.org/2000/09/xmldsig#"> <EncryptedKeyxmlns="http://www.w3.org/2001/04/xmlenc#"> <EncryptionMethodAlgorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" /> <KeyInfoxmlns="http://www.w3.org/2000/09/xmldsig#"> <KeyName>Rsa Key</KeyName> </KeyInfo> <CipherData> <CipherValue> lm3mfPX/94Zm3HgdbsmKiIxbrWM14t3/ugxs40BFOAHbIaCtwQ3gVQusFtOFVUoNVny01kgBCeh10rVEId djNZ/8luBNoCbHm8OLjgPLHVrT+G0c/LRpESJk2ni/Jy2sWKXlgejgSQ1W5NE53GZtG3s9hu+nk4OWxntS 6z3v7AM= </CipherValue> </CipherData> </EncryptedKey> </KeyInfo> <CipherData> <CipherValue> BCEGUV/dh1Imbcm5vn0Kn8NrD+EX+KemenR7x+VekwT1ZO6y5+jRyF4RDWMJCfJ1jHC36+MAfCdHuXN0rP B6hu5YUtX9VA5q5N0NGrs9AIpG+0ihuuS3HDzQe3P6nlI30m1h0pmL1yJBovY0i6fbCA6++GT2MdwCLERk +PVWmoq7p1q97n5pNzNqhVKCX45lhS5ySVS+MjJXVeTrcatftpvaUcjLsNcL2kMerzf5w/SU3AbLEuY04w dgYWX5tWzxqeUcghdlWLD0tQi8qyyfVfzXPYozR5sspWHdgqmAycrACHN2dcONWPjT4BanRWb1ouKuP8K+ 0CEFE/Hj2ChpYw== </CipherValue> </CipherData> </EncryptedData> </machineKey>
清单 3:web配置文件的加密代码
protected void btnEncrypt_Click(object sender, EventArgs e) { try { Configuration config = WebConfigurationManager.OpenWebConfiguration( "/Aspalliance1 "); ConfigurationSection machineKeySection = config.GetSection( "system.web/machineKey"); machineKeySection.SectionInformation.ProtectSection( "RSAProtectedConfigurationProvider"); machineKeySection.SectionInformation.ForceSave = true; config.Save(); Response.Write("<h2 style='color:red'>Encryption Succeed</h2>"); } catch (Exception ex) { Response.Write("<h2 style='color:red'>Error while encrypting</h2><br/>"); Response.Write(ex.Message); } }
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
相关专题
- .NET移动与嵌入式技术 (5963篇文章)
- .NET开发手册 (5664篇文章)
- ASP.NET教程 (8457篇文章)
- ASP.NET应用篇 (2638篇文章)
- .NET开发人员犯的6大安全错误 (6次浏览)
- 请跟我来--使用Ext搞个原型 (1次浏览)
- ASP.NET 3.5 Extensions带来什么 (1次浏览)
- 应用WEB标准会使ScrollTop属性失效! (0次浏览)
- Cache用法之缓存页面和缓存数据 (0次浏览)
- 支持正则表达式的UrlMapping (0次浏览)
- 关于ASP.NET 2.0的目录结构变化 (0次浏览)
- WPF中Closing窗体时调用Hide()方法异常 (0次浏览)
- 对象数组根据某属性列的灵活排序 (0次浏览)
- DB2 9和ASP.NET 2.0构建下一代应用程序 (0次浏览)



