📄 mainform.cs
字号:
if((myStream = openFileDialog1.OpenFile())!= null)
{
if(File.Exists(openFileDialog1.FileName))
{
Sanpack_rsa.hextxtlist.Clear();
StreamReader swReader = new StreamReader(myStream);
try
{
// If the file is not empty,
// read the application settings.
if(swReader.Peek() != -1)
{
String s="";
while(true)
{
s=swReader.ReadLine();
if(s==null)
{
textBox1.Text+="\r\nHEX文本读取完毕,共读入"+Sanpack_rsa.hextxtlist.Count.ToString()+
"行\r\n可以开始加解密操作:)\r\n";
break;
}
else
{
if(s.Substring(0,1)=="#")continue;
else Sanpack_rsa.hextxtlist.Add(s);
}
}
}
}
// If the end of the stream is reached before reading
// the four data values, ignore the error and use the
// default settings for the remaining values.
catch(EndOfStreamException excp)
{
textBox1.Text+="\r\nHEX文本读取完毕,共读入"+Sanpack_rsa.hextxtlist.Count.ToString()+
"行\r\n可以开始加解密操作:)\r\n";
//+"\r\n异常为 " + excp.GetType().Name.ToString();
}
finally
{
swReader.Close();
}
}
myStream.Close();
}
}
}
private void menuItem25_Click(object sender, System.EventArgs e)
{
if(Sanpack_rsa.charlist.Count==0)
{
emptymsg em=new emptymsg(this);
em.Show();
return;
}
Stream myStream ;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "Hex text files (*.hextxt)|*.hextxt|All files (*.*)|*.*" ;
saveFileDialog1.FilterIndex = 1 ;
saveFileDialog1.RestoreDirectory = true ;
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if((myStream=saveFileDialog1.OpenFile()) != null)
{
textBox1.Text+="\r\n正在对读入的文件进行处理,请稍候:)\r\n";
System.Threading.Thread.Sleep(500);
using (StreamWriter sw = new StreamWriter(myStream))
{
sw.WriteLine("# Sanpack.RSA.HexText");
sw.WriteLine("#___________________________________________");
Byte []b=new Byte[Sanpack_rsa.RSAstep];
Sanpack_rsa.result_hexstrings.Clear();
progressBar1.Minimum=0;
progressBar1.Maximum=Sanpack_rsa.charlist.Count;
for(int i=0;i<Sanpack_rsa.charlist.Count;i+=System.Convert.ToInt32(Sanpack_rsa.RSAstep))
{
for(int j=0;j<Sanpack_rsa.RSAstep;j++)
{
b[j]=System.Convert.ToByte(Sanpack_rsa.charlist[i+j]);
}
string s;
//only ASCII file can use this
//s=Sanpack_rsa.FromASCIIByteArray(b);
//Sanpack_rsa.RSA_san_en(s,Sanpack_rsa.RSAstep);
Sanpack_rsa.RSA_san_dn(b,Sanpack_rsa.RSAstep);
s=Sanpack_rsa.get_result_hexstring();
Sanpack_rsa.result_hexstrings.Add(s);
progressBar1.Value=i+1;
}
for(int i=0;i<Sanpack_rsa.result_hexstrings.Count;i++)
{
string hs=System.Convert.ToString(Sanpack_rsa.result_hexstrings[i]);
if(hs==null||hs=="")sw.WriteLine("0");
else sw.WriteLine(hs);
}
sw.WriteLine("#___________________________________________");
sw.Write("# ");
sw.WriteLine(DateTime.Now);
Sanpack_rsa.result_hexstrings.Clear();
}
myStream.Close();
textBox1.Text+="\r\n处理完成,新生成文件\r\n"+saveFileDialog1.FileName+"\r\n";
progressBar1.Value=0;
}
}
}
private void menuItem26_Click(object sender, System.EventArgs e)
{
if(Sanpack_rsa.hextxtlist.Count==0)
{
emptymsg em=new emptymsg(this);
em.Show();
return;
}
Stream myStream ;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*" ;
saveFileDialog1.FilterIndex = 2 ;
saveFileDialog1.RestoreDirectory = true ;
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if((myStream=saveFileDialog1.OpenFile()) != null)
{
textBox1.Text+="\r\n正在对十六进制文本进行处理,请稍候:)\r\n";
System.Threading.Thread.Sleep(500);
using (BinaryWriter bn = new BinaryWriter(myStream))
{
progressBar1.Minimum=0;
progressBar1.Maximum=Sanpack_rsa.hextxtlist.Count;
for(int i=0;i<Sanpack_rsa.hextxtlist.Count;i++)
{
Sanpack_rsa.RSA_san_en_hexstring(System.Convert.ToString(Sanpack_rsa.hextxtlist[i]));
for(uint j=0;j<Sanpack_rsa.RSAstep;j++)
{
bn.Write(Sanpack_rsa.get_result_byte(j));
}
progressBar1.Value=i+1;
}
}
myStream.Close();
textBox1.Text+="\r\n处理完成,新生成文件\r\n"+saveFileDialog1.FileName+"\r\n";
progressBar1.Value=0;
}
}
}
private void menuItem33_Click(object sender, System.EventArgs e)
{
settings sp=new settings(this);
sp.Show();
}
private void menuItem28_Click(object sender, System.EventArgs e)
{
Stream myStream;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\" ;
openFileDialog1.Filter = "RSA privatekey files (*.rsakey)|*.rsakey|RSA publickey files (*.rsakey_public)|*.rsakey_public|All files (*.*)|*.*" ;
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true ;
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
if((myStream = openFileDialog1.OpenFile())!= null)
{
if(File.Exists(openFileDialog1.FileName))
{
StreamReader swReader = new StreamReader(myStream);
Sanpack_rsa.result_hexstrings.Clear();
try
{
if(swReader.Peek() != -1)
{
String s="";
while(true)
{
s=swReader.ReadLine();
if(s==null)
{
break;
}
else
{
if(s.Substring(0,1)=="#")continue;
else Sanpack_rsa.result_hexstrings.Add(s);
}
}
if(Sanpack_rsa.result_hexstrings.Count==2)
{
//force e,n
Sanpack_rsa.force_e
(System.Convert.ToString(Sanpack_rsa.result_hexstrings[0]),
System.Convert.ToUInt32(
(System.Convert.ToString(Sanpack_rsa.result_hexstrings[0]).Length+1)/2)
);
Sanpack_rsa.force_n
(System.Convert.ToString(Sanpack_rsa.result_hexstrings[1]),
System.Convert.ToUInt32(
(System.Convert.ToString(Sanpack_rsa.result_hexstrings[1]).Length+1)/2)
);
textBox1.Text+="\r\n公共密钥(e,n)覆盖完毕\r\n请注意,其他参量并不进行匹配更新\r\n";
textBox1.Text+="\r\nn="+Sanpack_rsa.get_n()+"\r\nd="+Sanpack_rsa.get_e()+"\r\n";
}
}
}
catch(EndOfStreamException excp)
{
textBox1.Text+="\r\n公共密钥(e,n)覆盖完毕\r\n请注意,其他参量并不进行匹配更新\r\n";
//+"\r\n异常为 " + excp.GetType().Name.ToString();
}
finally
{
swReader.Close();
Sanpack_rsa.result_hexstrings.Clear();
}
}
myStream.Close();
}
}
}
private void menuItem30_Click(object sender, System.EventArgs e)
{
Stream myStream;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\" ;
openFileDialog1.Filter = "RSA privatekey files (*.rsakey)|*.rsakey|RSA publickey files (*.rsakey_public)|*.rsakey_public|All files (*.*)|*.*" ;
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = true ;
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
if((myStream = openFileDialog1.OpenFile())!= null)
{
if(File.Exists(openFileDialog1.FileName))
{
StreamReader swReader = new StreamReader(myStream);
Sanpack_rsa.result_hexstrings.Clear();
try
{
if(swReader.Peek() != -1)
{
String s="";
while(true)
{
s=swReader.ReadLine();
if(s==null)
{
break;
}
else
{
if(s.Substring(0,1)=="#")continue;
else Sanpack_rsa.result_hexstrings.Add(s);
}
}
if(Sanpack_rsa.result_hexstrings.Count==2)
{
//force d,n
Sanpack_rsa.force_d
(System.Convert.ToString(Sanpack_rsa.result_hexstrings[0]),
System.Convert.ToUInt32(
(System.Convert.ToString(Sanpack_rsa.result_hexstrings[0]).Length+1)/2)
);
Sanpack_rsa.force_n
(System.Convert.ToString(Sanpack_rsa.result_hexstrings[1]),
System.Convert.ToUInt32(
(System.Convert.ToString(Sanpack_rsa.result_hexstrings[1]).Length+1)/2)
);
textBox1.Text+="\r\n私有密钥(d,n)覆盖完毕\r\n请注意,其他参量并不进行匹配更新\r\n";
textBox1.Text+="\r\nn="+Sanpack_rsa.get_n()+"\r\nd="+Sanpack_rsa.get_d()+"\r\n";
}
}
}
catch(EndOfStreamException excp)
{
textBox1.Text+="\r\n私有密钥(d,n)覆盖完毕\r\n请注意,其他参量并不进行匹配更新\r\n";
//+"\r\n异常为 " + excp.GetType().Name.ToString();
}
finally
{
swReader.Close();
Sanpack_rsa.result_hexstrings.Clear();
}
}
myStream.Close();
}
}
}
private void menuItem9_Click(object sender, System.EventArgs e)
{
}
private void menuItem11_Click(object sender, System.EventArgs e)
{
}
private void menuItem6_Click(object sender, System.EventArgs e)
{
}
private void menuItem23_Click(object sender, System.EventArgs e)
{
}
private void menuItem34_Click(object sender, System.EventArgs e)
{
}
private void menuItem14_Click(object sender, System.EventArgs e)
{
}
private void menuItem17_Click(object sender, System.EventArgs e)
{
}
private void menuItem15_Click(object sender, System.EventArgs e)
{
ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
startInfo.Arguments = "http://3mn.net/www/bbs/index.asp?boardid=7";
Process process1=new Process ();
process1.StartInfo =startInfo;
process1.Start();
//System.Diagnostics.Process[] processList = System.Diagnostics.Process.GetProcessesByName("IEXPLORE");
//foreach (System.Diagnostics.Process process in processList)
//{
// System.Threading .Thread .Sleep (10000);
// process.Kill ();
//}
}
private void menuItem13_Click(object sender, System.EventArgs e)
{
ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
startInfo.Arguments = "spdn.3mn.net";
Process process1=new Process ();
process1.StartInfo =startInfo;
process1.Start();
}
private void menuItem1_Click(object sender, System.EventArgs e)
{
}
private void menuItem5_Click(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -