?? dsblmainframe.java
字號(hào):
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setFileFilter(new JAVAFileFilter3("en"));
int result = fileChooser.showOpenDialog(father);
if (result == JFileChooser.APPROVE_OPTION) {
File f = fileChooser.getSelectedFile();
try {
father.getJTextField6().setText(f.toString());
} catch (Exception e1) {
JOptionPane.showMessageDialog(father, e1.toString(), "錯(cuò)誤!",
JOptionPane.ERROR_MESSAGE);
}
}
}
}
/**
* This method initializes jButton9
*
* @return javax.swing.JButton
*/
private JButton getJButton9() {
if (jButton9 == null) {
jButton9 = new JButton();
jButton9.setBounds(new java.awt.Rectangle(423,217,106,22));
jButton9.setText("開始驗(yàn)證");
jButton9.addActionListener(new jb9ActionListener(this));
}
return jButton9;
}
private class jb9ActionListener implements java.awt.event.ActionListener {
private DSBLMainFrame father;
jb9ActionListener(DSBLMainFrame f) {
super();
father = f;
}
public void actionPerformed(java.awt.event.ActionEvent e) {
String md5digest=null;
try {
if(father.inspectPubKey!=null){
File ftemp = new File(father.getJTextField5().getText());
lyMD5 md5 = new lyMD5();
md5digest = md5.getMD5Digest(ftemp);
// java.sql.Date dtmp=new java.sql.Date(new
// java.util.Date().getTime());
father.getJTextPane().getDocument().insertString(
father.getJTextPane().getDocument().getLength(),
"(" + new java.util.Date() + ":)源文件"+ftemp.getPath()+"消息摘要=" + md5digest
+ "\n", sas);
File ft = new File(father.getJTextField6().getText());
FileInputStream in = new FileInputStream(ft);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
byte[] tmpbuf = new byte[1024];
int count = 0;
while ((count = in.read(tmpbuf)) != -1) {
bout.write(tmpbuf, 0, count);
tmpbuf = new byte[1024];
}
byte[] orgData = bout.toByteArray();
byte[] raw = lyRSA.decrypt(father.inspectPubKey, orgData);
String newdigest=new String(raw);
father.getJTextPane().getDocument().insertString(
father.getJTextPane().getDocument().getLength(),
"(" + new java.util.Date() + ":)解密后的摘要:" + newdigest
+ "\n", sas);
if(newdigest.equals(md5digest)) father.getJTextPane().getDocument().insertString(
father.getJTextPane().getDocument().getLength(),
"(" + new java.util.Date() + ":)驗(yàn)證結(jié)果:簽名比配。\n", sas);
else father.getJTextPane().getDocument().insertString(
father.getJTextPane().getDocument().getLength(),
"(" + new java.util.Date() + ":)驗(yàn)證結(jié)果:簽名不匹配。\n", sas);
}else {
JOptionPane.showMessageDialog(father, "請(qǐng)選擇密鑰,或生成它。",
"錯(cuò)誤!", JOptionPane.ERROR_MESSAGE);
}
} catch (FileNotFoundException e1) {
JOptionPane.showMessageDialog(father, "請(qǐng)輸入正確的文件名,或選擇文件。",
"錯(cuò)誤!", JOptionPane.ERROR_MESSAGE);
} catch (Exception e2) {
JOptionPane.showMessageDialog(father, e2.toString(), "錯(cuò)誤!",
JOptionPane.ERROR_MESSAGE);
}
}
}
/**
* This method initializes jPopupMenu2
*
* @return javax.swing.JPopupMenu
*/
private JPopupMenu getJPopupMenu2() {
if (jPopupMenu2 == null) {
jPopupMenu2 = new JPopupMenu();
jPopupMenu2.add(getJMenuItem14());
jPopupMenu2.addSeparator();
jPopupMenu2.add(getJMenuItem10());
jPopupMenu2.add(getJMenuItem11());
jPopupMenu2.addSeparator();
jPopupMenu2.add(getJMenuItem12());
jPopupMenu2.add(getJMenuItem13());
jPopupMenu2.addSeparator();
jPopupMenu2.add(getJMenuItem15());
}
return jPopupMenu2;
}
/**
* This method initializes jMenuItem10
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getJMenuItem10() {
if (jMenuItem10 == null) {
jMenuItem10 = new JMenuItem();
jMenuItem10.setText("刷新");
jMenuItem10.addActionListener(new Mytj10ActionListener(this));
}
return jMenuItem10;
}
private class Mytj10ActionListener implements java.awt.event.ActionListener {
private DSBLMainFrame father;
Mytj10ActionListener(DSBLMainFrame f) {
super();
father = f;
}
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
father.jTable1 = father.refreshJTable1();
} catch (Exception e1) {
System.out.println(e1);
}
}
}
/**
* This method initializes jMenuItem11
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getJMenuItem11() {
if (jMenuItem11 == null) {
jMenuItem11 = new JMenuItem();
jMenuItem11.setText("導(dǎo)入公鑰");
jMenuItem11.addActionListener(new Mytj11ActionListener(this));
}
return jMenuItem11;
}
private class Mytj11ActionListener implements java.awt.event.ActionListener {
private DSBLMainFrame father;
Mytj11ActionListener(DSBLMainFrame f) {
super();
father = f;
}
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
//MDialog dlg = new MDialog(null,this,"Query For Detail",true);
AddORSADialog dlg=new AddORSADialog(null,father,"添加驗(yàn)證公鑰:",true);
dlg.setSize(446, 313);
dlg.setResizable(false);
dlg.setVisible(true);
//if (dlg.flag==1) father.jTable = father.freshJTable();
} catch (Exception e1) {
System.out.println(e1);
}
}
}
/**
* This method initializes jMenuItem12
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getJMenuItem12() {
if (jMenuItem12 == null) {
jMenuItem12 = new JMenuItem();
jMenuItem12.setText("刪除行");
jMenuItem12.addActionListener(new Mytj12ActionListener(this));
}
return jMenuItem12;
}
private class Mytj12ActionListener implements java.awt.event.ActionListener {
private DSBLMainFrame father;
Mytj12ActionListener(DSBLMainFrame f) {
super();
father = f;
}
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
int[] rows=father.getJTable1().getSelectedRows();
int si=JOptionPane.showConfirmDialog(father,"確定刪除這"+rows.length+"條記錄嗎?\n注意 : 此操作無法恢復(fù)","請(qǐng)選擇",JOptionPane.YES_NO_OPTION);
if(si==JOptionPane.YES_OPTION) {
StringBuffer sb=new StringBuffer();
sb.append("delete from ORSA where id in (");
for(int i=0;i<rows.length-1;i++){
sb.append("?,");
}
sb.append("?)");
String psql=sb.toString();
con=father.getConnection();
PreparedStatement pst = con.prepareStatement(psql);
for(int i=0;i<rows.length;i++){
int id=Integer.parseInt((String)(father.getJTable1().getValueAt(rows[i],0)));
pst.setInt(i+1,id);
}
pst.executeUpdate();
father.jTable1=father.refreshJTable1();
father.getJTextPane().getDocument().insertString(father.getJTextPane().getDocument().getLength(),"(" + new java.util.Date() + ":) 已經(jīng)從公鑰庫中刪除這"+rows.length+"條記錄\n", sas);
}
} catch (Exception e1) {
try{
father.getJTextPane().getDocument().insertString(father.getJTextPane().getDocument().getLength(),"(" + new java.util.Date() + ":)系統(tǒng)異常=" + e1.toString()+ "\n", sas);
}catch(Exception e2){
System.out.println(e2);
}
}
}
}
/**
* This method initializes jMenuItem13
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getJMenuItem13() {
if (jMenuItem13 == null) {
jMenuItem13 = new JMenuItem();
jMenuItem13.setText("刪除所有記錄");
jMenuItem13.addActionListener(new Mytj13ActionListener(this));
}
return jMenuItem13;
}
private class Mytj13ActionListener implements java.awt.event.ActionListener {
private DSBLMainFrame father;
Mytj13ActionListener(DSBLMainFrame f) {
super();
father = f;
}
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
int si=JOptionPane.showConfirmDialog(father,"確定清空所有密鑰記錄嗎?\n注意 : 此操作無法恢復(fù)","請(qǐng)選擇",JOptionPane.YES_NO_OPTION);
if(si==JOptionPane.YES_OPTION) {
con = father.getConnection();
PreparedStatement pst = con
.prepareStatement("delete from ORSA");
pst.executeQuery();
pst.close();
father.jTable1=father.refreshJTable1();
father.getJTextPane().getDocument().insertString(father.getJTextPane().getDocument().getLength(),"(" + new java.util.Date() + ":) 公鑰庫所有記錄已經(jīng)清空\n", sas);
}
} catch (Exception e1) {
father.jTable1=father.refreshJTable1();
}
}
}
/**
* This method initializes jMenuItem14
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getJMenuItem14() {
if (jMenuItem14 == null) {
jMenuItem14 = new JMenuItem();
jMenuItem14.setText("使用該密鑰");
jMenuItem14.addActionListener(new Mytj14ActionListener(this));
}
return jMenuItem14;
}
private class Mytj14ActionListener implements java.awt.event.ActionListener {
private DSBLMainFrame father;
Mytj14ActionListener(DSBLMainFrame f) {
super();
father = f;
}
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
con=father.getConnection();
int row=father.getJTable1().getSelectedRow();
int id=Integer.parseInt((String)(father.getJTable1().getValueAt(row,0)));
PreparedStatement pst = con
.prepareStatement("select * from ORSA where id=?");
pst.setInt(1,id);
ResultSet rs = pst.executeQuery();
if (rs.next()){
RSAPublicKey ptemp=(RSAPublicKey)(new ObjectInputStream(new ByteArrayInputStream(rs.getBytes(4))).readObject());
father.inspectPubKey=ptemp;
father.getJTextField2().setText("來自公鑰庫id="+id+"密鑰");
}
rs.close();
} catch (Exception e1) {
try{
father.getJTextPane().getDocument().insertString(father.getJTextPane().getDocument().getLength(),"(" + new java.util.Date() + ":)系統(tǒng)異常=" + e1.toString()+ "\n", sas);
}catch(Exception e2){
System.out.println(e2);
}
}
}
}
/**
* This method initializes jMenuItem15
*
* @return javax.swing.JMenuItem
*/
private JMenuItem getJMenuItem15() {
if (jMenuItem15 == null) {
jMenuItem15 = new JMenuItem();
jMenuItem15.setText("輸出到文件");
jMenuItem15.addActionListener(new Mytj15ActionListener(this));
}
return jMenuItem15;
}
private class Mytj15ActionListener implements java.awt.event.ActionListener {
private DSBLMainFrame father;
Mytj15ActionListener(DSBLMainFrame f) {
super();
father = f;
}
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileFilter(new JAVAFileFilter1("pub"));
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int result = fileChooser.showSaveDialog(father);
if (result == JFileChooser.APPROVE_OPTION) {
File f = fileChooser.getSelectedFile();
String fileName=f.getName();
int index=fileName.lastIndexOf('.');
if (index<1){
f=new File(f.getPath()+".pub");
}
int si=JOptionPane.YES_OPTION;
if(f.exists())
si=JOptionPane.showConfirmDialog(father,"文件"+f.getPath()+"已經(jīng)存在,要覆蓋它嗎?確定覆蓋","文件存在",JOptionPane.YES_NO_OPTION);
if(si==JOptionPane.YES_OPTION) {
try {
con=father.getConnection();
int row=father.getJTable1().getSelectedRow();
int id=Integer.parseInt((String)(father.getJTable1().getValueAt(row,0)));
PreparedStatement pst = con
.prepareStatement("select * from ORSA where id=?");
pst.setInt(1,id);
ResultSet rs = pst.executeQuery();
RSAPublicKey r=null;
RSAPrivateKey p=null;
if (rs.next()){
r=(RSAPublicKey)(new ObjectInputStream(new ByteArrayInputStream(rs.getBytes(4))).readObject());
//p=(RSAPrivateKey)(new ObjectInputStream(new ByteArrayInputStream(rs.getBytes(5))).readObject());
}
rs.close();
FileOutputStream w=new FileOutputStream(f);
ObjectOutputStream ow = new ObjectOutputStream(w);
ow.writeObject(r);
ow.flush();
ow.close();
pst.close();
father.getJTextPane().getDocument().insertString(father.getJTextPane().getDocument().getLength(),"(" + new java.util.Date() + ":) 已經(jīng)將公鑰id="+id+"保存到文件:"+f.getPath()+"\n", sas);
} catch (Exception e1) {
JOptionPane.showMessageDialog(father, e1.toString(), "錯(cuò)誤!",
JOptionPane.ERROR_MESSAGE);
}
}
}
} catch (Exception e1) {
try{
father.getJTextPane().getDocument().insertString(father.getJTextPane().getDocument().getLength(),"(" + new java.util.Date() + ":)系統(tǒng)異常=" + e1.toString()+ "\n", sas);
}catch(Exception e2){
System.out.println(e2);
}
}
}
}
public static void main(String[] args){
DSBLMainFrame frame=new DSBLMainFrame();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
frame.setVisible(true);
}
} // @jve:decl-index=0:visual-constraint="10,10"
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -