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

📄 girl_gui.java

📁 这是一个文本加密、解密系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package IS_Project1;

import java.awt.CardLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.Key;

import javax.swing.ButtonGroup;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class Girl_GUI extends JFrame implements GUI_interface {
    private My_Cipher myCipher;
    private Key_Manager key_center;
    private MAC_Center mac_center;
    private String selected_key_algorithm_name;
    private String selected_algorithm_name;
    
    private JMenuBar menuBar;
    private JMenu mode_menu;
    private JMenuItem encryption_item, authentication_item;
    private Icon the_Icon;
    private JTextField encryp_file_choose_field, authen_file_choose_field;
    private JRadioButton symmetric_button, asymmetric_button;
    private ButtonGroup radio_Group;
    private JLabel encryp_file_choose_label, cipher_choose_label, icon_label, authen_file_label;
    private JButton encryp_file_choose_button, encryp_button, decryp_button,
                    authen_file_choose_button, verify_button, sign_button;
    private JTextArea encryp_output_area, authen_specify_area;
    private JComboBox cipher_combobox;
    private JScrollPane encryp_scroll_area, authen_speicfy_scroll;
    private JPanel encryp_panel, authen_panel, deck;
    private CardLayout cardManager;
    
    private String cipher_name[] = {"DES Cipher (56 bits Key)",
                                        "AES Cipher (128 bits Key)", 
                                        "RSA Cipher (1024 bits Key)"};
    private String key_algorithm_name[] = {"DES", "AES", "RSA"};
    private String algorithm_name[] = {"DES/ECB/PKCS5Padding", "AES/ECB/PKCS5Padding", "RSA/ECB/PKCS1Padding"};
    private int key_len[] = {56, 128, 1024};
    
    private Icon button_icons[] = {new ImageIcon("./button_icon/lock.jpg"), 
            new ImageIcon("./button_icon/key.jpg")};
    
    private int encryp_mode;

    //constructor
    public Girl_GUI(My_Cipher myCipher, Key_Manager key_center, MAC_Center mac_center)
    {
        super("Girl's Interface--Message Securer");
        
        this.myCipher = myCipher;
        this.key_center = key_center;
        this.mac_center = mac_center;
        
        //default encryption/decryption mode--DES
        this.encryp_mode = GUI_interface.SYMMETRIC_CIPHER;
        this.selected_key_algorithm_name = this.key_algorithm_name[0];
        this.selected_algorithm_name = this.algorithm_name[0];
        
        this.register_in_keyCenter();
        this.key_center.generate_girl_key_pair(key_algorithm_name[2], key_len[2], this.myCipher);
        
        this.register_in_macCenter();
        
        this.build_GUI();
    }
    
    //register the girl cipher in the key center
    private void register_in_keyCenter()
    {
        this.key_center.register_girlcipher_entry(this.myCipher);
    }
    
    //register the girl cipher in the mac center
    private void register_in_macCenter()
    {
        this.mac_center.register_girl_cipher(this.myCipher);
    }
    
    //Used only by the attacker.
    public void modify_file_content(){}
    public void save_modify_file(){}

    public void output_to_textarea(String cipher_text)
    {
        this.encryp_output_area.setText(cipher_text);
    }

    //selects a file from a filechooser, returns a File object.
    private File select_file() 
    {
        JFileChooser filechooser = new JFileChooser();
        filechooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        int result = filechooser.showOpenDialog(null);

        if (result == JFileChooser.CANCEL_OPTION)
        {
            return null;
        }

        File encryp_fileName = filechooser.getSelectedFile();

        if (encryp_fileName == null || encryp_fileName.getName().equals("")
                || !encryp_fileName.exists())
        {
            JOptionPane.showMessageDialog(null," 非法的文件名. 请重新选择 .","文件名非法",JOptionPane.ERROR_MESSAGE);
            encryp_file_choose_field.setText("");
            return null;
        }
        
        return encryp_fileName;
    }
    
    //saves a target file, returns the File object.
    private File select_dst_file() 
    {
        JFileChooser filechooser = new JFileChooser();
        filechooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        int result = filechooser.showSaveDialog(null);

        if (result == JFileChooser.CANCEL_OPTION)
        {
             return null;
        }

        File destFile = filechooser.getSelectedFile();
        return destFile;
    }
    
    //alternates the panel show in the GUI(encryp_panel and authen_panel)
    public void show_the_panel(String which_panel)
    {
        this.cardManager.show(this.deck, which_panel);
    }

    //builds the girl GUI
    public void build_GUI()
    {
        //build the menu bar
        this.mode_menu = new JMenu("服务选择(Service)");
        this.encryption_item = new JMenuItem("加(解)密消息");
        this.authentication_item = new JMenuItem("MAC报文认证");
        this.encryption_item.addActionListener(encryp_mode_handler);
        this.authentication_item.addActionListener(authen_mode_handler);
        this.mode_menu.add(this.encryption_item);
        this.mode_menu.add(this.authentication_item);
        
        this.menuBar = new JMenuBar();
        setJMenuBar(this.menuBar);
        this.menuBar.add(this.mode_menu);
        
        setLayout(null);
        
        this.the_Icon = new ImageIcon("./icon_label/girl.JPG");
        this.icon_label = new JLabel(the_Icon);
        this.icon_label.setBounds(-10, 0, 603, 115);
        add(this.icon_label);
        
        this.deck = new JPanel();
        this.cardManager = new CardLayout();
        this.deck.setLayout(this.cardManager);
        this.deck.setBounds(0, 0, 600, 660);
        
        //build the encryption/decryption mode panel
        this.encryp_panel = new JPanel();
        this.encryp_panel.setLayout(null);
        
        this.symmetric_button = new JRadioButton("对称加密模式", true);
        this.asymmetric_button = new JRadioButton("非对称加密模式", false);
        RadioButtonHandler cipher_mode_handler = new RadioButtonHandler();
        this.symmetric_button.addItemListener(cipher_mode_handler);
        this.asymmetric_button.addItemListener(cipher_mode_handler);
        this.radio_Group = new ButtonGroup();
        this.radio_Group.add(this.symmetric_button);
        this.radio_Group.add(this.asymmetric_button);
        
        this.symmetric_button.setBounds(20, 130, 120, 30);
        this.asymmetric_button.setBounds(180, 130, 120, 30);
        this.encryp_panel.add(this.symmetric_button);
        this.encryp_panel.add(this.asymmetric_button);
        
        this.encryp_file_choose_label = new JLabel("目标文件路径:");
        this.encryp_file_choose_label.setBounds(20, 180, 100, 30);
        this.encryp_panel.add(this.encryp_file_choose_label);
        
        this.encryp_file_choose_field = new JTextField();
        this.encryp_file_choose_field.setBounds(120, 180, 350, 30);
        this.encryp_panel.add(this.encryp_file_choose_field);
        
        this.encryp_file_choose_button = new JButton(" 浏览 ");
        this.encryp_file_choose_button.setBounds(490, 180, 80, 30);
        this.encryp_panel.add(this.encryp_file_choose_button);
        
        this.cipher_choose_label = new JLabel("加密系统类型:");
        this.cipher_choose_label.setBounds(20, 240, 100, 30);
        this.encryp_panel.add(this.cipher_choose_label);
        
        this.cipher_combobox = new JComboBox();
        this.cipher_combobox.addItem(cipher_name[0]);
        this.cipher_combobox.addItem(cipher_name[1]);
        this.cipher_combobox.setMaximumRowCount(3);
        ComboBoxItemHandler combobox_handler = new ComboBoxItemHandler();
        this.cipher_combobox.addItemListener(combobox_handler);
        this.cipher_combobox.setBounds(120, 240, 200, 30);
        this.encryp_panel.add(this.cipher_combobox);
        
        this.encryp_button = new JButton(" 加密 ", this.button_icons[0]);
        this.encryp_button.setBounds(120, 300, 110, 33);
        this.encryp_panel.add(this.encryp_button);
        
        this.decryp_button = new JButton(" 解密 ", this.button_icons[1]);
        this.decryp_button.setBounds(330, 300, 110, 33);
        this.encryp_panel.add(this.decryp_button);
        
        ButtonEventHandler buttonHandler = new ButtonEventHandler();
        this.encryp_button.addActionListener(buttonHandler);
        this.decryp_button.addActionListener(buttonHandler);
        this.encryp_file_choose_button.addActionListener(buttonHandler);
 
        this.encryp_output_area = new JTextArea(12,38);
        Color color = new Color(255, 204, 255);
        this.encryp_output_area.setBackground(color);
        this.encryp_output_area.setSelectedTextColor(Color.BLUE);
        this.encryp_output_area.setEditable(false);
        this.encryp_scroll_area = new JScrollPane(this.encryp_output_area);
        this.encryp_scroll_area.setBounds(35, 360, 520, 290);
        this.encryp_panel.add(this.encryp_scroll_area);
        

⌨️ 快捷键说明

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