www.pudn.com > Encrypt.rar > Form1.cs


using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using System.Security.Cryptography; 
using System.IO; 
using System.Globalization; 
namespace Encrypt 
{ 
    public partial class Form1 : Form 
    { 
        public Form1() 
        { 
            InitializeComponent(); 
        } 
 
        private void button1_Click(object sender, EventArgs e) 
        { 
 
            String text = this.richTextBox1.Text; 
            if (text.Trim().Length == 0) 
            { 
                MessageBox.Show("请输入要加密或解密的字符!", "系统提示"); 
                return; 
            } 
            try 
            { 
                String temp = Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(text)).Replace("+", "%2B"); 
                temp = temp.Insert(1, "Q"); 
                temp.Substring(0, 1); 
                this.richTextBox2.Text = temp; 
            } 
            catch (Exception ex) 
            { 
 
                MessageBox.Show("解密失败,请确认你输入的加密字符是否正确!", "系统提示"); 
            } 
 
        } 
        private void button2_Click(object sender, EventArgs e) 
        { 
            String text = this.richTextBox1.Text; 
            if (text.Trim().Length == 0) 
            { 
                MessageBox.Show("请输入要加密或解密的字符!", "系统提示"); 
                return; 
            } 
            try 
            { 
                text = text.Remove(1, 1); 
                this.richTextBox2.Text = System.Text.Encoding.Default.GetString(Convert.FromBase64String(text.Replace("%2B", "+"))); 
            } 
            catch (Exception ex) 
            { 
                MessageBox.Show("解密失败,请确认你输入的解密字符是否正确!", "系统提示"); 
            } 
 
        } 
 
        private void button3_Click(object sender, EventArgs e) 
        { 
            AboutBox1 about = new AboutBox1(); 
            about.ShowDialog(); 
        } 
 
         
 
         
    } 
}