📄 form1.cs
字号:
textMd52.Text=reGx.Replace("-","");
reGx2=reGx.Replace("-","");
using (StreamWriter sw = new StreamWriter("md5.txt"))
{
sw.Write(reGx2);
}
}
private void button8_Click_1(object sender, System.EventArgs e)
{
string reGex,reGex2;
byte[] bt=UTF8Encoding.UTF8.GetBytes(textMd51.Text.Trim());
MD5CryptoServiceProvider objMD5;
objMD5=new MD5CryptoServiceProvider();
byte[] output=objMD5.ComputeHash (bt);
reGex=BitConverter.ToString (output);
reGex2=reGex.Replace("-","");
textMd52.Text=reGex2;
using (StreamWriter sw = new StreamWriter("md5.txt"))
{
sw.Write(textMd52.Text);
}
}
private void button9_Click_1(object sender, System.EventArgs e)
{
StreamReader objReader = new StreamReader("md52.txt");
string sLine="";
sLine = objReader.ReadLine();
objReader.Close();
textSee.Text=sLine;
}
private void button6_Click_1(object sender, System.EventArgs e)
{
string comparePass;
string compare,reGex;
compare=textName.Text+textPass.Text;
byte[] bt=UTF8Encoding.UTF8.GetBytes(compare);
MD5CryptoServiceProvider objMD5;
objMD5=new MD5CryptoServiceProvider();
byte[] output=objMD5.ComputeHash (bt);
comparePass=BitConverter.ToString (output);
reGex=comparePass.Replace("-","");
StreamReader objReader = new StreamReader("md5.txt");
string sLine="";
sLine = objReader.ReadLine();
objReader.Close();
if(reGex==sLine)
{
MessageBox.Show("检测成功","提示!",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
MessageBox.Show("用户名或者密码错误!","提示!",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
private void button10_Click_1(object sender, System.EventArgs e)
{
Application.Exit();
}
private void button14_Click(object sender, System.EventArgs e)
{
crypt=new RSACryptoServiceProvider();
publickey=crypt.ToXmlString(false);
richText1.Text="密匙:\n"+publickey+"\n";
privatekey=crypt.ToXmlString(true);
string info="公匙:\n"+privatekey+"\n";
richText1.AppendText(info);
crypt.Clear();
}
private void button13_Click(object sender, System.EventArgs e)
{
using (StreamWriter sw = new StreamWriter("publickey.txt"))
{
sw.Write(publickey);
}
}
private void button12_Click(object sender, System.EventArgs e)
{
using (StreamWriter sw = new StreamWriter("privatekey.txt"))
{
sw.Write(privatekey);
}
}
private void button17_Click(object sender, System.EventArgs e)
{
try
{
StreamReader objReader = new StreamReader("PublicKey.txt");
string sLine="";
sLine = objReader.ReadToEnd();
//textSee.Text=sLine.ToString();
textPub.Text=sLine;
publicK=sLine;
objReader.Close();
readpubkey=true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button16_Click(object sender, System.EventArgs e)
{
if(textBox1.Text =="")
{
MessageBox.Show("加密文字信息不能为空!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
if(readpubkey==false)
{
MessageBox.Show("请检查公钥所在的文件是否损坏!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
try
{
crypt=new RSACryptoServiceProvider();
UTF8Encoding enc=new UTF8Encoding();
bytes=enc.GetBytes(textBox1.Text);
crypt.FromXmlString(publicK);// readpublickey
bytes = crypt.Encrypt( bytes,false );
string encryttext=enc.GetString(bytes);
richText2.Text="加密结果:\n"+encryttext;
}
catch
{
MessageBox.Show("请检查公匙是否损坏!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
private void button18_Click(object sender, System.EventArgs e)
{
try
{
/*readprivatekey = ReadPrivateKey();*/
StreamReader objReader = new StreamReader("PrivateKey.txt");
string sLine="";
sLine = objReader.ReadToEnd();
//textSee.Text=sLine.ToString();
textPri.Text=sLine;
privateK=sLine;
objReader.Close();
readprikey = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button15_Click(object sender, System.EventArgs e)
{
if(readprikey==false)
{
MessageBox.Show("请检查密匙所在的文件是否损坏!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
try
{
UTF8Encoding enc=new UTF8Encoding();
byte [] decryptbyte;
crypt.FromXmlString (privateK) ;//readprivatekey
decryptbyte = crypt.Decrypt( bytes,false );
string decrypttext=enc.GetString( decryptbyte );
richText3.Text = "解密结果:\n" + decrypttext;
}
catch
{
MessageBox.Show("请检查私匙是否损坏!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
private void button19_Click(object sender, System.EventArgs e)
{
OpenFileDialog open = new OpenFileDialog( );
open.Filter="Text File (*.txt)|*.txt|All Files (*.*)|*.*";
open.ShowDialog();
textBox2.Text=open.FileName;
openla = true;
}
private void button20_Click(object sender, System.EventArgs e)
{
try
{
SaveFileDialog save=new SaveFileDialog();
save.Filter="File Text (*.txt)|*.txt|All File (*.*)|*.*";
save.ShowDialog();
textBox3.Text=save.FileName;
savela = true;
}
catch
{
MessageBox.Show("请输入文件名字!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
}
private void button23_Click(object sender, System.EventArgs e)
{
//readpublickey = ReadPublicKey();
try
{
/*readpublickey = ReadPublicKey();*/
StreamReader objReader = new StreamReader("PublicKey.txt");
string sLine="";
sLine = objReader.ReadToEnd();
//textSee.Text=sLine.ToString();
textPub.Text=sLine;
publicK=sLine;
objReader.Close();
readpubkey=true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button24_Click(object sender, System.EventArgs e)
{
//readprivatekey =ReadPrivateKey();
try
{
/*readprivatekey = ReadPrivateKey();*/
StreamReader objReader = new StreamReader("PrivateKey.txt");
string sLine="";
sLine = objReader.ReadToEnd();
//textSee.Text=sLine.ToString();
textPri.Text=sLine;
privateK=sLine;
objReader.Close();
readprikey = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button21_Click(object sender, System.EventArgs e)
{
if(readpubkey != true)
{
MessageBox.Show("请检查公匙所在的文件是否破坏!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
if(openla==true&&savela==true)
{
crypt=new RSACryptoServiceProvider();
crypt.FromXmlString(publicK);// readpublickey
UTF8Encoding enc=new UTF8Encoding();
//读取原文件到一个string 去啊
StreamReader sr=new StreamReader(textBox2.Text,Encoding.Default);
string textinfo=sr.ReadToEnd();
sr.Close();
richText4.AppendText( "原文件内容:\n" + textinfo + "\n" );
//开始加密
string readinfo=EncryptFile(textinfo,textBox3.Text);
richText5.AppendText( "加密文件已经保存到:" + textBox3.Text + "\n" );
richText5.AppendText( "加密结果:\n" + readinfo);
}
else
MessageBox.Show("请选择你要加密的文件或者要保存的文件!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
private void button22_Click(object sender, System.EventArgs e)
{
{
if(readprikey==false)
{
MessageBox.Show("请检查密匙所在的文件是否破坏!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
if(openla==true&&savela==true)
{
try
{
crypt=new RSACryptoServiceProvider();
crypt.FromXmlString(privateK);// readprivatekey
string decryptinfo = DecryptFile(textBox2.Text,textBox3.Text);
richText5.AppendText( "解密文件已经保存到:" + textBox3.Text+ "\n" );
richText5.AppendText("解密结果:\n" + decryptinfo);
}
catch
{
MessageBox.Show("请检查密匙文件是否和公匙相对应或者密匙文件损坏!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
}
else
MessageBox.Show("请选择你要解密的文件或者要保存的文件!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void button25_Click(object sender, System.EventArgs e)
{
textBox2.Text="";
textBox3.Text="";
richText4.Text="";
richText5.Text="";
textPub.Text="";
textPri.Text="";
}
private void button27_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
private void button26_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
private void button10_Click(object sender, System.EventArgs e)
{
string reGex,reGex2;
byte[] bt=UTF8Encoding.UTF8.GetBytes(textPass1.Text.Trim());
MD5CryptoServiceProvider objMD5;
objMD5=new MD5CryptoServiceProvider();
byte[] output=objMD5.ComputeHash (bt);
reGex=BitConverter.ToString (output);
reGex2=reGex.Replace("-","");
if (textName1.Text=="" || textPass1.Text =="")
{
MessageBox.Show("您提交的信息不完全","提示!");
return;
}
try
{
string strCon = " Provider=Microsoft.Jet.OLEDB.4.0; Data Source=usermd5.mdb ";
OleDbConnection myConn=new OleDbConnection(strCon);
string strInsert = "INSERT INTO cc_admin(usernam,passwor) VALUES ('"
+ textName1.Text +"','"
+ reGex2 +"')";
myConn.Open();
OleDbCommand myCmd = new OleDbCommand(strInsert,myConn);
myCmd.ExecuteNonQuery();
myConn.Close();
MessageBox.Show("添加用户成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void button28_Click(object sender, System.EventArgs e)
{
string reGex,reGex2;
byte[] bt=UTF8Encoding.UTF8.GetBytes(textPass.Text.Trim());
MD5CryptoServiceProvider objMD5;
objMD5=new MD5CryptoServiceProvider();
byte[] output=objMD5.ComputeHash (bt);
reGex=BitConverter.ToString (output);
reGex2=reGex.Replace("-","");
if (textName.Text=="" || textPass.Text =="")
{
MessageBox.Show("您提交的信息不完全","提示!");
return;
}
string strCon = " Provider=Microsoft.Jet.OLEDB.4.0; Data Source=usermd5.mdb ";
OleDbConnection myConn=new OleDbConnection(strCon);
string strSel = "select count(*) from cc_admin where usernam='"+textName.Text+"' and passwor='"+reGex2+"'";
myConn.Open();
OleDbCommand myCmd = new OleDbCommand(strSel,myConn);
int Count=(int)myCmd.ExecuteScalar();
myConn.Close();
if(Count==0)
{
MessageBox.Show("没有这个用户!请核对您是否输入正确!","提示!");
textName.Text="";
textPass.Text="";
return;
}
try
{
MessageBox.Show("通过验证!","提示!",MessageBoxButtons.OK,MessageBoxIcon.Information);
textName.Text="";
textPass.Text="";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -