⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rsa.java

📁 整体思路 用createkey.java 文件来产生秘钥
💻 JAVA
字号:
import java.awt.*;import java.awt.event.*;import java.math.*;import javax.swing.*;import javax.swing.border.*;import java.io.*;class window extends JFrame implements ActionListener{	BigInteger p;	BigInteger q;	BigInteger n;	BigInteger e;	BigInteger d;	JTextField tp;	JTextField tq;	JTextField tn;	JTextField te;	JTextField td;	JTextField dirming;	JTextField dirmi;	JTextField dirhuan;	createkey key;	jiami jiami;	jiemi jiemi;	JButton bkey;	JButton bmingwen;	JButton bmiwen;	JButton bhuanyuan;	JButton bjiami;	JButton bjiemi;	Box box1,box2,box3,box4,box5,box6;	FileDialog dmingwen,dmiwen,dhuanyuan;	File fmingwen,fmiwen,fhuanyuan;	boolean keyflag=false;	window(String s)	{		super(s);				dmingwen=new FileDialog(this,"选择明文",FileDialog.LOAD);		dmiwen=new FileDialog(this,"选择密文",FileDialog.LOAD);		dhuanyuan=new FileDialog(this,"选择还原文件",FileDialog.LOAD);		dmingwen.addWindowListener(new WindowAdapter()																				{																					public void windowClosing(WindowEvent e)																					{																						dmingwen.setVisible(false);																					}																				});		dmiwen.addWindowListener(new WindowAdapter()		{			public void windowClosing(WindowEvent e)			{				dmiwen.setVisible(false);			}		});		dhuanyuan.addWindowListener(new WindowAdapter()		{			public void windowClosing(WindowEvent e)			{				dhuanyuan.setVisible(false);			}		});						key=new createkey();		p=key.p;		q=key.q;		n=key.n;		e=key.e;		d=key.d;				setLayout(null);		bkey=new JButton("生成密钥 ");		bkey.addActionListener(this);		bmingwen=new JButton("   选择明文   ");		bmingwen.addActionListener(this);		bmiwen=new JButton("   选择密文   ");		bmiwen.addActionListener(this);		bhuanyuan=new JButton("选择还原文件");		bhuanyuan.addActionListener(this);		bjiami=new JButton("加密");		bjiami.addActionListener(this);		bjiemi=new JButton("解密");		bjiemi.addActionListener(this);		tp=new JTextField(40);		tq=new JTextField(15);		tn=new JTextField(15);		td=new JTextField(15);		te=new JTextField(15);		dirming=new JTextField(15);		dirmi=new JTextField(15);		dirhuan=new JTextField(15);		dirming.setEditable(false);		dirmi.setEditable(false);		dirhuan.setEditable(false);				box1=Box.createVerticalBox();		box2=Box.createVerticalBox();		box3=Box.createHorizontalBox();		box4=Box.createVerticalBox();		box5=Box.createVerticalBox();		box6=Box.createHorizontalBox();						box1.add(new JLabel("p"));		box1.add(Box.createVerticalStrut(16));		box1.add(new JLabel("q"));		box1.add(Box.createVerticalStrut(16));		box1.add(new JLabel("n"));		box1.add(Box.createVerticalStrut(16));		box1.add(new JLabel("d"));		box1.add(Box.createVerticalStrut(16));		box1.add(new JLabel("e"));		box1.add(Box.createVerticalStrut(16));		box1.add(new JLabel("明文文件根目录"));		box1.add(Box.createVerticalStrut(16));		box1.add(new JLabel("密文文件根目录"));		box1.add(Box.createVerticalStrut(16));		box1.add(new JLabel("还原文件根目录"));		box2.add(tp);		box2.add(Box.createVerticalStrut(8));		box2.add(tq);		box2.add(Box.createVerticalStrut(8));		box2.add(tn);		box2.add(Box.createVerticalStrut(8));		box2.add(td);		box2.add(Box.createVerticalStrut(8));		box2.add(te);		box2.add(Box.createVerticalStrut(8));		box2.add(dirming);		box2.add(Box.createVerticalStrut(8));		box2.add(dirmi);		box2.add(Box.createVerticalStrut(8));		box2.add(dirhuan);		box3.add(box1);		box3.add(Box.createHorizontalStrut(10));		box3.add(box2);				box4.add(bmingwen);		box4.add(Box.createVerticalStrut(8));		box4.add(bmiwen);		box4.add(Box.createVerticalStrut(8));		box4.add(bhuanyuan);		box5.add(bjiami);		box5.add(Box.createVerticalStrut(8));		box5.add(bjiemi);		box6.add(box4);		box6.add(Box.createHorizontalStrut(60));		box6.add(box5);				setBounds(150,150,500,530);		add(bkey);		bkey.setBounds(20, 20, 120, 30);		add(box3);		box3.setBounds(40,90,430,250);		add(box6);		box6.setBounds(20, 360, 280, 100);		addWindowListener(new WindowAdapter()														{															public void windowClosing(WindowEvent e)															{																System.exit(0);															}														});		setVisible(true);		validate();	}	public void actionPerformed(ActionEvent ee)	{		if(ee.getSource()==bkey)		{			tp.setText(p.toString());			tq.setText(q.toString());			tn.setText(n.toString());			te.setText(e.toString());			td.setText(d.toString());			keyflag=true;		}		if(ee.getSource()==bmingwen)		{			dmingwen.setVisible(true);			if(dmingwen.getFile()!=null)			{				fmingwen=new File(dmingwen.getDirectory(),dmingwen.getFile());				dirming.setText(fmingwen.getAbsolutePath());			}		}		if(ee.getSource()==bmiwen)		{			dmiwen.setVisible(true);			if(dmiwen.getFile()!=null)			{				fmiwen=new File(dmiwen.getDirectory(),dmiwen.getFile());				dirmi.setText(fmiwen.getAbsolutePath());			}		}		if(ee.getSource()==bhuanyuan)		{			dhuanyuan.setVisible(true);			if(dhuanyuan.getFile()!=null)			{				fhuanyuan=new File(dhuanyuan.getDirectory(),dhuanyuan.getFile());				dirhuan.setText(fhuanyuan.getAbsolutePath());			}		}		if(ee.getSource()==bjiami)		{			if(keyflag==false)				JOptionPane.showMessageDialog(this, "请生成密钥", "警告", JOptionPane.WARNING_MESSAGE);			else if(fmingwen==null)				JOptionPane.showMessageDialog(this, "请选择明文文件", "警告", JOptionPane.WARNING_MESSAGE);			else if(fmiwen==null)				JOptionPane.showMessageDialog(this, "请选择密文文件", "警告", JOptionPane.WARNING_MESSAGE);			else{				jiami=new jiami(n,e,d,fmingwen,fmiwen);				JOptionPane.showMessageDialog(this, "已经成功加密", "加密", JOptionPane.WARNING_MESSAGE);			}		}		if(ee.getSource()==bjiemi)		{			if(keyflag==false)				JOptionPane.showMessageDialog(this, "请生成密钥", "警告", JOptionPane.WARNING_MESSAGE);			else if(fmiwen==null)				JOptionPane.showMessageDialog(this, "请选择密文文件", "警告", JOptionPane.WARNING_MESSAGE);			else if(fhuanyuan==null)				JOptionPane.showMessageDialog(this, "请选择还原文件", "警告", JOptionPane.WARNING_MESSAGE);			else{				jiemi=new jiemi(n,e,d,fmiwen,fhuanyuan);				JOptionPane.showMessageDialog(this, "已经成功解密", "解密", JOptionPane.WARNING_MESSAGE);			}		}	}}public class rsa{	public static void main(String args[])	{		new window("RSA加密及解密"	);	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -