開始動手吧,先做一個操作用的網頁並且在上面放兩個按鈕,
一個用來加密字串一個用來解密字串,然後在按鈕的Click事件中寫入下面的程式。

    protected void Encryption(object sender, EventArgs e)
    {

        Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
        ConfigurationSection section = config.ConnectionStrings;
       
        if (!section.SectionInformation.IsProtected)
        {
            section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
            section.SectionInformation.ForceSave = true;
            config.Save(ConfigurationSaveMode.Modified);
        }
    }

    protected void Decrypting(object sender, EventArgs e)
    {
        Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
        ConfigurationSection section = config.ConnectionStrings;
       
        if (section.SectionInformation.IsProtected)
        {
            section.SectionInformation.UnprotectSection();
            section.SectionInformation.ForceSave = true;
            config.Save(ConfigurationSaveMode.Modified);
        }
    }


資料來源:http://www.purecs.net/thread/topic402_1.aspx


arrow
arrow
    全站熱搜

    Roger 發表在 痞客邦 留言(0) 人氣()