zoukankan      html  css  js  c++  java
  • C#中将字符串转成 Base64 编码 (加密--解密)

     1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Base64.aspx.cs" Inherits="Base64" %>
     2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     3 <html xmlns="http://www.w3.org/1999/xhtml" >
     4 <head runat="server">
     5     <title> Base64加密解密
     6 </title>
     7 </head>
     8 <body>
     9     <form id="form1" runat="server">
    10     <div>
    11         <span style="font-size: 24pt; color: #006633" mce_style="font-size: 24pt; color: #006633">           
    12                               Base64加密解密</span><br />
    13         <br />
    14         <br />
    15     <asp:TextBox ID="txtChar" runat="server"></asp:TextBox> 
    16     <asp:Button ID="btnEncrypt" runat="server" Text="加密" OnClick="btnBase64_Click" />
    17         <asp:Button ID="btnExtract" runat="server" OnClick="Button1_Click" Text="解密" /><br />
    18         <br />
    19     <asp:Label ID="lblMessage" runat="server" Width="211px" ></asp:Label></div>
    20     </form>
    21 </body>
    22 </html>
    23 
    24 
    25 
    26 
    27 
    28 using System;
    29 using System.Data;
    30 using System.Configuration;
    31 using System.Collections;
    32 using System.Web;
    33 using System.Web.Security;
    34 using System.Web.UI;
    35 using System.Web.UI.WebControls;
    36 using System.Web.UI.WebControls.WebParts;
    37 using System.Web.UI.HtmlControls;
    38 public partial class Base64 : System.Web.UI.Page
    39 {
    40     protected void Page_Load(object sender, EventArgs e)
    41     {
    42     }
    43     protected void btnBase64_Click(object sender, EventArgs e)
    44     {
    45         string a = txtChar.Text;
    46         byte[] b = System.Text.Encoding.Default.GetBytes(a);
    47         lblMessage.Text =  Convert.ToBase64String(b);
    48     }
    49     protected void Button1_Click(object sender, EventArgs e)
    50     {
    51         string a = txtChar.Text;
    52         byte[] c = Convert.FromBase64String(a);
    53         lblMessage.Text = System.Text.Encoding.Default.GetString(c);
    54     }
    55 }
  • 相关阅读:
    contentSize,contentOffset,contentInset整理
    UITableViewCell的移动
    怎么修改Xcode新项目或新文件最上面的Creat By XXX
    objc_setAssociatedObject 关联对象
    Python strip()方法
    Python函数中*args和**kwargs来传递变长参数的用法
    python闭包
    Grand Garden思维题
    Circles Inside a Square(几何题)
    Matrix Transformation(模拟)
  • 原文地址:https://www.cnblogs.com/lyhsblog/p/7131420.html
Copyright © 2011-2022 走看看