📄 jiami.java
字号:
/* * jiami.java * * Created on 2007年10月12日, 下午8:26 */package a;/** * * @author guowen */import java.awt.*;import java.awt.event.*;import java.io.*;import java.security.*;import javax.crypto.*;import javax.crypto.spec.*;import java.security.interfaces.*;import javax.crypto.interfaces.*;import java.net.*;final class jiami extends javax.swing.JFrame { /** * Creates new form jiami */ public jiami() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); jScrollPane2 = new javax.swing.JScrollPane(); jTextArea2 = new javax.swing.JTextArea(); jLabel1 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jLabel3 = new javax.swing.JLabel(); jButton2 = new javax.swing.JButton(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jmi1 = new javax.swing.JMenuItem(); jMenuItem1 = new javax.swing.JMenuItem(); jMenuItem2 = new javax.swing.JMenuItem(); jMenu2 = new javax.swing.JMenu(); jmi2 = new javax.swing.JMenuItem(); jMenu5 = new javax.swing.JMenu(); jmi31 = new javax.swing.JMenuItem(); jmi32 = new javax.swing.JMenuItem(); jmi33 = new javax.swing.JMenuItem(); jMenu3 = new javax.swing.JMenu(); jmi4 = new javax.swing.JMenuItem(); jmi5 = new javax.swing.JMenuItem(); jMenu4 = new javax.swing.JMenu(); jmi6 = new javax.swing.JMenuItem(); jmi7 = new javax.swing.JMenuItem(); jmi8 = new javax.swing.JMenuItem(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jTextArea1.setColumns(20); jTextArea1.setRows(5); jScrollPane1.setViewportView(jTextArea1); jTextArea2.setColumns(20); jTextArea2.setEditable(false); jTextArea2.setRows(5); jTextArea2.setText("状态:\n"); jTextArea2.setName(""); // NOI18N jScrollPane2.setViewportView(jTextArea2); jLabel1.setText("消息摘要:"); jButton1.setText("发送加密的消息"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jLabel3.setText("接收方的IP地址:"); jButton2.setText("发送DES密钥"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jMenu1.setText("文件"); jmi1.setText("保存消息"); jmi1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jmi1ActionPerformed(evt); } }); jMenu1.add(jmi1); jMenuItem1.setText("打开消息文件"); jMenuItem1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem1ActionPerformed(evt); } }); jMenu1.add(jMenuItem1); jMenuItem2.setText("清空消息"); jMenuItem2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem2ActionPerformed(evt); } }); jMenu1.add(jMenuItem2); jMenuBar1.add(jMenu1); jMenu2.setText("消息"); jmi2.setText("计算消息摘要"); jmi2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jmi2ActionPerformed(evt); } }); jMenu2.add(jmi2); jMenu5.setText("数字签名"); jmi31.setText("输入私钥"); jmi31.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jmi31ActionPerformed(evt); } }); jMenu5.add(jmi31); jmi32.setText("输入消息摘要"); jmi32.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jmi32ActionPerformed(evt); } }); jMenu5.add(jmi32); jmi33.setText("数字签名"); jmi33.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jmi33ActionPerformed(evt); } }); jMenu5.add(jmi33); jMenu2.add(jMenu5); jMenu3.setText("加密"); jmi4.setText("生成密钥"); jmi4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jmi4ActionPerformed(evt); } }); jMenu3.add(jmi4); jmi5.setText("加密"); jmi5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jmi5ActionPerformed(evt); } }); jMenu3.add(jmi5); jMenu2.add(jMenu3); jMenuBar1.add(jMenu2); jMenu4.setText("密钥"); jmi6.setText("输入对方公钥"); jmi6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jmi6ActionPerformed(evt); } }); jMenu4.add(jmi6); jmi7.setText("输入要加密的密钥"); jmi7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jmi7ActionPerformed(evt); } }); jMenu4.add(jmi7); jmi8.setText("使用对方公钥加密"); jmi8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jmi8ActionPerformed(evt); } }); jMenu4.add(jmi8); jMenuBar1.add(jMenu4); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 536, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 436, Short.MAX_VALUE))) .addContainerGap()) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 536, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 217, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(jTextField1)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton1) .addComponent(jButton2)) .addContainerGap()) ); pack(); }// </editor-fold> private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { try{ String ip=jiami.jTextField3.getText(); Socket s=new Socket(ip,6123); OutputStream ops=s.getOutputStream(); InputStream ips=s.getInputStream(); FileInputStream fis=new FileInputStream("RSA加密.dat"); int num=fis.available(); byte buf[]=new byte[num]; int len=fis.read(buf); ops.write(buf,0,len); ops.close(); fis.close(); s.close(); }catch(Exception e){ System.out.println(e); } } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { try{ String ip=jiami.jTextField3.getText(); Socket s=new Socket(ip,6000); OutputStream ops=s.getOutputStream(); InputStream ips=s.getInputStream(); FileInputStream fis=new FileInputStream("message.txt"); int num=fis.available(); byte buf[]=new byte[num]; int len=fis.read(buf); ops.write(buf,0,len); ops.close(); fis.close(); s.close(); }catch(Exception e){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -