protected void Page_Load(object sender, EventArgs e)
{ var url= string.Format("ScriptResource.axd?d={0}", PageEncryptString("Q|~/web.config|#|xlsb"));
//var info = F.Studio.Web.Utility.MachineKeyUtil.GenerateMachineKey();
//Response.Write("D->" + info.Decryption +":" + info.DecryptionKey +"
"); //Response.Write("V->" + info.Validation +":" + info.ValidationKey);
}
public static string PageDecryptString(string input) {
Type type = typeof(System.Web.UI.Page);
object o = Activator.CreateInstance(type);
System.Reflection.MethodInfo mi = type.GetMethod("DecryptString", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static, null, new Type[] { typeof(string) }, null);
object result = mi.Invoke(o, new object[] { input }); return result.ToString();
}
public static string PageEncryptString(string input)
{
Type type = typeof(System.Web.UI.Page);
object o = Activator.CreateInstance(type); System.Reflection.MethodInfo mi = type.GetMethod("EncryptString", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static, null, new Type[] { typeof(string) }, null); object result = mi.Invoke(o, new object[] { input }); return result.ToString();
}
本文介绍了一种在ASP.NET应用中实现字符串加密和解密的方法。通过反射调用System.Web.UI.Page类中的静态非公开方法EncryptString和DecryptString来完成对字符串的安全处理。这些方法可以用于保护配置文件或其他敏感信息。
233

被折叠的 条评论
为什么被折叠?



