您的位置:首页 > 编程语言 > C#

C#中将字符串转成 Base64 编码

2010-10-08 18:22 274 查看
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Base64.aspx.cs" Inherits="Base64" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title> Base64加密解密
</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <span style="font-size: 24pt; color: #006633" mce_style="font-size: 24pt; color: #006633">           
                              Base64加密解密</span><br />
        <br />
        <br />
    <asp:TextBox ID="txtChar" runat="server"></asp:TextBox> 
    <asp:Button ID="btnEncrypt" runat="server" Text="加密" OnClick="btnBase64_Click" />
        <asp:Button ID="btnExtract" runat="server" OnClick="Button1_Click" Text="解密" /><br />
        <br />
    <asp:Label ID="lblMessage" runat="server" Width="211px" ></asp:Label></div>
    </form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Base64 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void btnBase64_Click(object sender, EventArgs e)
    {
        string a = txtChar.Text;
        byte[] b = System.Text.Encoding.Default.GetBytes(a);
        lblMessage.Text =  Convert.ToBase64String(b);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string a = txtChar.Text;
        byte[] c = Convert.FromBase64String(a);
        lblMessage.Text = System.Text.Encoding.Default.GetString(c);
    }
}










using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Base64 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void btnBase64_Click(object sender, EventArgs e)
    {
        string a = txtChar.Text;
        byte[] b = System.Text.Encoding.Default.GetBytes(a);
        lblMessage.Text =  Convert.ToBase64String(b);
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string a = txtChar.Text;
        byte[] c = Convert.FromBase64String(a);
        lblMessage.Text = System.Text.Encoding.Default.GetString(c);
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: