日期:2010-05-11 浏览次数:20415 次
下面的代码实现了一个可逆加密的方法。可以用于对Cookie,QueryString等加密处理。
查看例子
VB.net代码
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="EncString.<a href="http://dev.21tx.com/web/asp/" target="_blank">ASP</a>x.vb"
Inherits="aspx<a href="http://dev.21tx.com/web/" target="_blank">Web</a>.EncString" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>一个可逆加密的例子</title>
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="<a href="http://dev.21tx.com/web/javascript/" target="_blank">JavaScript</a>">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<asp:Label id="Label1" runat="server"></asp:Label>
<p align="center">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:TextBox id="TextBox1" runat="server" Width="96%"></asp:TextBox>
<asp:RadioButtonList id="RadioButtonList1" runat="server" Font-Bold="True"
RepeatDirection="Horizontal" AutoPostBack="True" OnSelectedIndexChanged="ShowRes">
</asp:RadioButtonList>
<asp:TextBox id="TextBox2" runat="server" Width="96%"></asp:TextBox>
</FONT>
</form>
</p>
</body>
</HTML>
后端代码EncString.aspx.vb:
Imports System
Imports System.IO
Imports System.Xml
Imports System.Text
Imports System.Security.Cryptography
Public Class EncString
Inherits System.Web.UI.Page
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents RadioButtonList1 As System.Web.UI.WebControls.RadioButtonList
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
'Put user code to initialize the page here
Label1.Text = "<h3 align='center'>一个可逆加密的例子</h3>"
If Not IsPostBack Then
Dim MyList As New ArrayList()
MyList.Add("加密")