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

📄 rsa.java

📁 用java写的RSA加密解密程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package yh;

import javax.crypto.Cipher;
import javax.swing.JFileChooser;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.JRadioButton;
import java.awt.Rectangle;
import java.io.*;
import java.security.*;

import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JButton;
import javax.swing.SwingConstants;
import javax.swing.JTextField;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import java.awt.Font;


public class Rsa extends JFrame {

	private static final long serialVersionUID = 1L;

	private JRadioButton jRadioButton = null;

	private JRadioButton jRadioButton1 = null;

	private JLabel jLabel = null;

	private JLabel jLabel1 = null;

	private JTextArea jTextArea1 = null;

	private JScrollPane jScrollPane = null;

	private JScrollPane jScrollPane1 = null;

	private JScrollPane jScrollPane2 = null;

	private JScrollPane jScrollPane3 = null;
	
	private JScrollPane jScrollPane4 = null;
    
	private JScrollPane jScrollPane5 = null;
	
	private JScrollPane jScrollPane6 = null;

	private JTextArea jTextArea = null;
	
	private JTextArea jTextArea4 = null;
	
	private JTextArea jTextArea5 = null;
	
	private JTextArea jTextArea6 = null;

	private JButton jButton1 = null;

	private JButton jButton2 = null;

	private JButton jButton = null;

	private JButton jButton3 = null;

	private JButton jButton11 = null;

	private JButton jButton21 = null;

	private JButton jButton22 = null;

	private JButton jButton12 = null;

	private JButton jButton31 = null;

	private JTextArea jTextArea2 = null;

	private JTextArea jTextArea3 = null;

	private JLabel jLabel2 = null;

	private JLabel jLabel21 = null;

	private JLabel jLabel3 = null;

	private JLabel jLabel31 = null;

	private JPanel jContentPane = null;
	
	private JFileChooser jFileChooser = null;

	PublicKey pubkey=null,signpubkey=null;
    
	PrivateKey prikey=null,signprikey=null;
	
	String Algorithm="RSA";  //  @jve:decl-index=0:
	String text1,text2;

	private JLabel jLabel311 = null;

	private JButton jButton121 = null;

	private JButton jButton311 = null;

	private JLabel jLabel4 = null;

	private JButton jButton24 = null;

	private JLabel jLabel22 = null;

	private JLabel jLabel23 = null;

	private JLabel jLabel5 = null;

	private JTextField jTextField = null;

	private JButton jButton221 = null;

	private JButton jButton211 = null;

	private JButton jButton212 = null;

	private JButton jButton213 = null;

	private JButton jButton222 = null;

	private JButton jButton223 = null;

	private JButton jButton224 = null;

	private JButton jButton214 = null;

	private JRadioButton jRadioButton2 = null;

	private JLabel jLabel6 = null;

	private JRadioButton getJRadioButton() {
		if (jRadioButton == null) {
			jRadioButton = new JRadioButton();
			jRadioButton.setBounds(new Rectangle(358, 17, 20, 20));
			jRadioButton.setToolTipText("选择发送模式");
			jRadioButton.addFocusListener(new java.awt.event.FocusAdapter() {
				public void focusGained(java.awt.event.FocusEvent e) {
					
					jRadioButton1.setSelected(false);
					jRadioButton2.setSelected(false);
					jButton311.setEnabled(false);
					jButton31.setEnabled(false);
					jButton2.setEnabled(true);
					jButton24.setEnabled(false);
					jTextArea1.setText("");
					jTextArea4.setText("");
					
				}
			});
		}
		return jRadioButton;
	}

	
	private JRadioButton getJRadioButton1() {
		if (jRadioButton1 == null) {
			jRadioButton1 = new JRadioButton();
			jRadioButton1.setBounds(new Rectangle(358, 35, 20, 20));
			jRadioButton1.setToolTipText("选择接收模式");
			jRadioButton1.addFocusListener(new java.awt.event.FocusAdapter() {
				public void focusGained(java.awt.event.FocusEvent e) {
					jRadioButton.setSelected(false);
					jRadioButton2.setSelected(false);
					jButton121.setEnabled(false);
					jButton12.setEnabled(false);
					jButton2.setEnabled(false);
					jButton24.setEnabled(true);
					jTextArea1.setText("");
					jTextArea4.setText("");
					
					
				}
			});
		}
		return jRadioButton1;
	}

	
	private JTextArea getJTextArea1() {
		if (jTextArea1 == null) {
			jTextArea1 = new JTextArea();
			jTextArea1.setEditable(false);
			jTextArea1.setFont(new Font("\u5fae\u8f6f\u96c5\u9ed1", Font.PLAIN, 13));
		}
		return jTextArea1;
	}

	private JScrollPane getJScrollPane() {

		if (jScrollPane == null) {
			try {
				jScrollPane = new JScrollPane();
				jScrollPane.setBounds(new Rectangle(20, 60, 360, 280));
				jScrollPane.setViewportView(getJTextArea());

			} catch (java.lang.Throwable e) {
				
			}
		}
		return jScrollPane;
	}

	private JScrollPane getJScrollPane1() {

		if (jScrollPane1 == null) {
			try {
				jScrollPane1 = new JScrollPane();
				jScrollPane1.setBounds(new Rectangle(420, 60, 360, 140));
				jScrollPane1.setViewportView(getJTextArea1());
			} catch (java.lang.Throwable e) {
				
			}
		}
		return jScrollPane1;
	}

	private JScrollPane getJScrollPane2() {

		if (jScrollPane2 == null) {
			try {
				jScrollPane2 = new JScrollPane();
				jScrollPane2.setBounds(new Rectangle(20, 405, 360, 65));
				jScrollPane2.setViewportView(getJTextArea2());

			} catch (java.lang.Throwable e) {
				
			}
		}
		return jScrollPane2;
	}

	private JScrollPane getJScrollPane3() {

		if (jScrollPane3 == null) {
			try {
				jScrollPane3 = new JScrollPane();
				jScrollPane3.setBounds(new Rectangle(420, 405, 360, 65));
				jScrollPane3.setViewportView(getJTextArea3());

			} catch (java.lang.Throwable e) {
				// TODO: Something
			}
		}
		return jScrollPane3;
	}
	private JScrollPane getJScrollPane4() {

		if (jScrollPane4 == null) {
			try {
				jScrollPane4 = new JScrollPane();
				jScrollPane4.setBounds(new Rectangle(420, 219, 360, 120));
				jScrollPane4.setViewportView(getJTextArea4());

			} catch (java.lang.Throwable e) {
				// TODO: Something
			}
		}
		return jScrollPane4;
	}
	
	private JScrollPane getJScrollPane5() {

		if (jScrollPane5 == null) {
			try {
				jScrollPane5 = new JScrollPane();
				jScrollPane5.setBounds(new Rectangle(20, 490, 360, 65));
				jScrollPane5.setViewportView(getJTextArea5());

			} catch (java.lang.Throwable e) {
				// TODO: Something
			}
		}
		return jScrollPane5;
	}
	private JScrollPane getJScrollPane6() {

		if (jScrollPane6 == null) {
			try {
				jScrollPane6 = new JScrollPane();
				jScrollPane6.setBounds(new Rectangle(420, 490, 360, 65));
				jScrollPane6.setViewportView(getJTextArea6());

			} catch (java.lang.Throwable e) {
				// TODO: Something
			}
		}
		return jScrollPane6;
	}

	
	private JTextArea getJTextArea() {
		if (jTextArea == null) {
			jTextArea = new JTextArea();
			jTextArea.setFont(new Font("\u5fae\u8f6f\u96c5\u9ed1", Font.PLAIN, 13));
			jTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
				public void keyTyped(java.awt.event.KeyEvent e) {
					if (jTextArea.getText().equals("")){
						jButton12.setEnabled(false);
						jButton1.setEnabled(false);
					}
					else{
						if (jButton211.isEnabled()){
							jButton12.setEnabled(true);
						}
					}
					
					
				}
			});
			
		}
		return jTextArea;
	}private JTextArea getJTextArea4() {
		if (jTextArea4 == null) {
			jTextArea4 = new JTextArea();
			jTextArea4.setEditable(false);
			jTextArea4.setFont(new Font("\u5fae\u8f6f\u96c5\u9ed1", Font.PLAIN, 13));
		}
		return jTextArea4;
	}

	
	private JButton getJButton1() {
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setBounds(new Rectangle(197, 36, 84, 22));
			jButton1.setEnabled(false);
			jButton1.setText("保存文本");
			jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					saveFile(0);
				}
			});
		}
		return jButton1;
	}

	
	private JButton getJButton2() {
		if (jButton2 == null) {
			jButton2 = new JButton();
			jButton2.setBounds(new Rectangle(275, 344, 105, 23));
			jButton2.setText("生成签名密钥");
			jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					try {
						KeyPairGenerator keygen = KeyPairGenerator.getInstance("RSA");
						 KeyPair keys=keygen.generateKeyPair(); // 生成密钥组
					     signpubkey=keys.getPublic();
					     signprikey=keys.getPrivate();
					     jTextArea2.setText(signpubkey.toString());
					     jTextArea3.setText(signprikey.toString());
						
					} catch (Exception e1) {
						
					}					
					jButton21.setEnabled(true);
					jButton212.setEnabled(true);
					if (!jTextArea4.getText().equals("")){
						jButton121.setEnabled(true);
					}
				}
			});
		}
		return jButton2;
	}

	
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setBounds(new Rectangle(102, 36, 81, 22));
			jButton.setText("读取明文");
			jButton.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					loadFile(0);
					
				}
			});

⌨️ 快捷键说明

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