http://lucky_love.www1.dotnetplayground.com/
The following example implements an reversible encryption example function. The code is very simple, this is not explained here. code show as below:
Encstring.aspx
<% @ Page language = "vb" autoeventwireup = "false" codebehind = "encString.aspx.vb" inherits = "aspxweb.encstring"%>
Imports SystemImports System.IOImports System.XmlImports System.TextImports System.Security.CryptographyPublic 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 RadioButtonList1 As System.Web.UI.WebControls.RadioButtonList # Region "Web Form Designer Generated Code" 'This call is required by the Web Form Designer.
{} DIM IV () AS BYTE = {& H12, & H34, & HAB, & H78, & H90, & Hab, & HCD, & HEF} try bykey = system.text.encoding.utf8.getbytes (Strench ") DIM DES AS NEW DESCryptoServiceProvider () Dim inputByteArray () As Byte = Encoding.UTF8.GetBytes (strText) Dim ms As New MemoryStream () Dim cs As New CryptoStream (ms, des.CreateEncryptor (byKey, IV), CryptoStreamMode.Write) cs.Write ( inputByteArray, 0, inputByteArray.Length) cs.FlushFinalBlock () Return Convert.ToBase64String (ms.ToArray ()) Catch ex As Exception Return ex.Message End Try End function 'decryption function Private Shared function decrypt (ByVal strText As String, _ ByVal sDecrKey As String) As String Dim byKey () As Byte = {} Dim IV () As Byte = {& H12, & H34, & H56, & H78, & H90, & HAB, & HCD, & HEF} Dim inputByteArray (strText.Length) As Byte Try Bykey = system.text.Encoding.utf8.getbytes (left (sdecrkey, 8)) Dim des new descryptoserviceProvider () InputByTearray = Convert.Fromb ase64String (strText) Dim ms As New MemoryStream () Dim cs As New CryptoStream (ms, des.CreateDecryptor (byKey, IV), CryptoStreamMode.Write) cs.Write (inputByteArray, 0, inputByteArray.Length) cs.FlushFinalBlock () Dim encoding As System.Text.Encoding = System.Text.Encoding.UTF8 Return encoding.GetString (ms.ToArray ()) Catch ex As Exception Return ex.Message End Try End Function Public Sub showRes (ByVal sender As Object, _ ByVal e As system.eventargs) Handles RadiobuttonList1.Selected Indexchanged IF RadiobuttonList1.SelectedIndex = 0 Then TextBox2.text =