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

📄 rsasupport.java

📁 jpeg2000编解码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	} else if(displayType==DISPLAY_PRIVATE) {	    delBut.addActionListener(new ActionListener() {		    public void actionPerformed(ActionEvent e) {			rsaKeyMng.removePrivKey((String)listPriv.						getSelectedValue());			mngKeyDialog.setVisible(false);			mngKeyDialog = null;		    }		});	    selectBut.addActionListener(new ActionListener() {		    public void actionPerformed(ActionEvent e) {			curPrivKey = (String)listPriv.getSelectedValue();			mngKeyDialog.setVisible(false);			mngKeyDialog = null;		    }		});	} else {	    delBut.addActionListener(new ActionListener() {		    public void actionPerformed(ActionEvent e) {			rsaKeyMng.removePubKey((String)listPub.					       getSelectedValue());			mngKeyDialog.setVisible(false);			mngKeyDialog = null;		    }		});	    selectBut.addActionListener(new ActionListener() {		    public void actionPerformed(ActionEvent e) {			curPubKey = (String)listPub.getSelectedValue();			mngKeyDialog.setVisible(false);			mngKeyDialog = null;		    }		});	}	content.add(commandPan);	mngKeyDialog.pack();	mngKeyDialog.setVisible(true);    }    /** Create the user interface to save RSA keys */    public void createSaveKeyUI(Main mainFrame) {	sKDialog = new JDialog(mainFrame,"Save public/private key",true);	Container content = sKDialog.getContentPane();	content.setLayout(new GridLayout(4,1));	// ---- Choose between public and private ----	JPanel chPan = new JPanel();	ButtonGroup pubPrivGrp = new ButtonGroup();	pubBut = new JRadioButton("Public",true);	pubPrivGrp.add(pubBut);	chPan.add(pubBut);	JRadioButton privBut = new JRadioButton("Private",false);	pubPrivGrp.add(privBut);	chPan.add(privBut);	content.add(chPan);	// ---- Exponent ----	JPanel expPan = new JPanel();	expPan.setBorder(BorderFactory.createTitledBorder("Exponent"));	expTF = new JTextField("",30);	expPan.add(expTF);	content.add(expPan);	// ---- Modulus ----	JPanel modPan = new JPanel();	modPan.setBorder(BorderFactory.createTitledBorder("Modulus"));	modTF = new JTextField("",30);	modPan.add(modTF);	content.add(modPan);	// ---- Save ----	JPanel savePan = new JPanel();	savePan.add(new JLabel("Name:"));	keyNameTF = new JTextField("Key name",10);	savePan.add(keyNameTF);	JButton okButton = new JButton("Save");	okButton.addActionListener(new ActionListener() {		public void actionPerformed(ActionEvent e) {		    if(pubBut.isSelected() && keyNameTF.getText()!="" &&		       expTF.getText()!="" && modTF.getText()!="") {			if(!rsaKeyMng.			   savePublicKey(keyNameTF.getText(),					 new BigInteger(expTF.getText()),					 new BigInteger(modTF.getText()))) {			    JOptionPane.				showMessageDialog(null,						  "Public Key is already "+						  "existing. "+						  "Remove the old one before "+						  "or use an other name.",						  "Error",						  JOptionPane.ERROR_MESSAGE);			    return;			}		    } else if(keyNameTF.getText()!="" && expTF.getText()!="" &&			      modTF.getText()!="") {			if(!rsaKeyMng.			   savePrivateKey(keyNameTF.getText(),					  new BigInteger(expTF.getText()),					  new BigInteger(modTF.getText()))) {			    JOptionPane.				showMessageDialog(null,						  "Private Key is already "+						  "existing. "+						  "Remove the old one before "+						  "or use an other name.",						  "Error",						  JOptionPane.ERROR_MESSAGE);			    return;			}		    }		}	    });	savePan.add(okButton);	JButton cancelButton = new JButton("Cancel");	cancelButton.addActionListener(new ActionListener() {		public void actionPerformed(ActionEvent ae) {		    sKDialog.setVisible(false);		    sKDialog = null;		}	    });	savePan.add(cancelButton);	content.add(savePan);	sKDialog.pack();	sKDialog.setVisible(true);    }    /** Create the user interface to generate and save RSA keys pairs */    public void createKeyGenUI(Main mainFrame) {	// Create JDialog and its layout	gKDialog = new JDialog(mainFrame,"Generate RSA keys pair",true);	Container content = gKDialog.getContentPane();	content.setLayout(new GridLayout(5,1));	// ---- Public key ----	JPanel pubPan = new JPanel();	pubPan.setBorder(BorderFactory.createTitledBorder("Public exponent"));	pubExpTF = new JTextField("",30);	pubExpTF.setEditable(false);	pubPan.add(pubExpTF);	content.add(pubPan);	// ---- Private key ----	JPanel privPan = new JPanel();	privPan.setBorder(BorderFactory.			  createTitledBorder("Private exponent"));	privExpTF = new JTextField("",30);	privExpTF.setEditable(false);	privPan.add(privExpTF);	content.add(privPan);	// ---- Modulus ----	JPanel modPan = new JPanel();	modPan.setBorder(BorderFactory.createTitledBorder("Modulus"));	pubModTF = new JTextField("",30);	pubModTF.setEditable(false);	modPan.add(pubModTF);	content.add(modPan);	// ---- Generate pair ----	JPanel genPan = new JPanel(new GridLayout(1,2));		    	// Modulus length	JPanel modLenPan = new JPanel();	modLenPan.add(new JLabel("Modulus length (bits):"));	tfModLen = new JTextField("128",4);	modLenPan.add(tfModLen);	genPan.add(modLenPan);	// Generate button	JPanel genButPan = new JPanel();	genBut = new JButton("Generate Pair");	genBut.addActionListener(new ActionListener() {		public void actionPerformed(ActionEvent e) {		    int modLen = (new Integer(tfModLen.getText())).intValue();		    rsaProducer = new RSAKeyProducer(genBut,keySaveBut,						     privExpTF,pubExpTF,						     pubModTF,modLen);		    Thread thRsa = new Thread(rsaProducer);		    thRsa.start();		}	    });	genButPan.add(genBut);	genPan.add(genButPan);	content.add(genPan);		    	// ---- Save ----	JPanel savePan = new JPanel(new GridLayout(1,2));	// Keys pair Name	JPanel keyNamePan = new JPanel();	keyNamePan.add(new JLabel("Name:"));	keyNameTF = new JTextField("Key",10);	keyNamePan.add(keyNameTF);	savePan.add(keyNamePan);	// Save keys pair	JPanel keySavePan = new JPanel();	keySaveBut = new JButton("Save");	keySaveBut.setEnabled(false);	keySaveBut.addActionListener(new ActionListener() {		public void actionPerformed(ActionEvent e) {		    if(keyNameTF.getText()!="" && pubExpTF.getText()!="" &&		       pubModTF.getText()!="") {			if(!rsaKeyMng.			   savePublicKey(keyNameTF.getText(),					 new BigInteger(pubExpTF.getText()),					 new BigInteger(pubModTF.getText()))) {			    JOptionPane.				showMessageDialog(null,						  "Public key is already "+						  "existing. "+						  "Remove the old one before "+						  "or use an other name.",						  "Error",						  JOptionPane.ERROR_MESSAGE);			    return;			}		    }		    if(keyNameTF.getText()!="" && privExpTF.getText()!="" &&		       pubModTF.getText()!="") {			if(!rsaKeyMng.			   savePrivateKey(keyNameTF.getText(),					  new BigInteger(privExpTF.getText()),					  new BigInteger(pubModTF.getText()))){			    JOptionPane.				showMessageDialog(null,						  "Private key is already "+						  "existing. "+						  "Remove the old one before "+						  "or use an other name.",						  "Error",						  JOptionPane.ERROR_MESSAGE);			    return;			}		    }		    gKDialog.setVisible(false);		    gKDialog = null;		}	    });	keySavePan.add(keySaveBut);	savePan.add(keySavePan);	content.add(savePan);		    	gKDialog.pack();	gKDialog.setVisible(true);    }}

⌨️ 快捷键说明

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