using System; using System.Text; using System.Windows.Forms; namespace Base64ConvertTool { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { if(string.IsNullOrEmpty(textBoxSrc.Text)) { return; } string strText = textBoxSrc.Text; byte[] byteText = Encoding.UTF8.GetBytes(strText); string strbase64 = Convert.ToBase64String(byteText); textBoxbase64.Text = strbase64; //校验一下 byte[] checkbyte = Convert.FromBase64String(strbase64); string checkstr = Encoding.UTF8.GetString(checkbyte); if(checkstr != strText) { MessageBox.Show("convert error!"); } } } }