📄 girl_gui.java
字号:
//build the authentication mode panel
this.authen_panel = new JPanel();
this.authen_panel.setLayout(null);
this.authen_file_label = new JLabel("目标文件路径:");
this.authen_file_label.setBounds(20, 200, 100, 30);
this.authen_panel.add(this.authen_file_label);
this.authen_file_choose_field = new JTextField();
this.authen_file_choose_field.setBounds(120, 200, 350, 30);
this.authen_panel.add(this.authen_file_choose_field);
this.authen_file_choose_button = new JButton(" 浏览 ");
this.authen_file_choose_button.setBounds(490, 200, 80, 30);
this.authen_panel.add(this.authen_file_choose_button);
this.sign_button = new JButton("生成MAC");
this.sign_button.setBounds(140, 280, 100, 35);
this.authen_panel.add(this.sign_button);
this.verify_button = new JButton("报文认证");
this.verify_button.setBounds(360, 280, 100, 35);
this.authen_panel.add(this.verify_button);
this.authen_file_choose_button.addActionListener(buttonHandler);
this.sign_button.addActionListener(buttonHandler);
this.verify_button.addActionListener(buttonHandler);
this.authen_specify_area = new JTextArea(12, 38);
Color authen_area_color = new Color(217, 217, 243);
this.authen_specify_area.setBackground(authen_area_color);
this.authen_specify_area.setEditable(false);
this.authen_specify_area.setSelectedTextColor(Color.RED);
this.authen_specify_area.setText(" " +
" MAC生成&认证说明\n" +
" " +
"~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
" (1)该消息认证模型使用的是Java内置的HmacMD5算法。\n\n" +
" (2)若要对一份报文进行MAC签名或者认证,请首先选择一个目标文件。\n\n" +
" (3)为了安全起见,该程序开发者强烈建议您先进行MAC签名,再作加密处理。");
this.authen_speicfy_scroll = new JScrollPane(this.authen_specify_area);
this.authen_speicfy_scroll.setBounds(55, 370, 480, 260);
this.authen_panel.add(this.authen_speicfy_scroll);
this.deck.add(this.encryp_panel, this.encryption_item.getText());
this.deck.add(this.authen_panel, this.authentication_item.getText());
add(this.deck);
pack();
setSize(600,730);
setLocation(650, 30);
setResizable(false);
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
//judges the validity of the encryption/decryption input src file
private boolean judge_encryp_input()
{
String a = this.encryp_file_choose_field.getText();
File file = new File(a);
if (a.equals(""))
{
JOptionPane.showMessageDialog(null," 请选择一个需要进行加密/解密的文件 ! ","选择文件",JOptionPane.INFORMATION_MESSAGE);
this.encryp_file_choose_field.setText("");
return false;
}
else if (!file.exists())
{
JOptionPane.showMessageDialog(null," 文件路径出错 ! 请重新选择 .","找不到文件",JOptionPane.ERROR_MESSAGE);
this.encryp_file_choose_field.setText("");
return false;
}
else
{
return true;
}
}
//judges the basic validity of the authentication input src file
private boolean judge_authen_input()
{
String a = this.authen_file_choose_field.getText();
File file = new File(a);
if (a.equals(""))
{
JOptionPane.showMessageDialog(null," 请选择一个需要进行MAC签名/认证的文件 ! ","选择文件",JOptionPane.INFORMATION_MESSAGE);
this.authen_file_choose_field.setText("");
return false;
}
else if (!file.exists())
{
JOptionPane.showMessageDialog(null," 文件路径出错 ! 请重新选择 .","找不到文件",JOptionPane.ERROR_MESSAGE);
this.authen_file_choose_field.setText("");
return false;
}
else
{
return true;
}
}
//gets the encryption/decryption input src file object from the file choose field
private File get_encryp_input_file()
{
String a = this.encryp_file_choose_field.getText();
File input_file = new File(a);
return input_file;
}
//gets the authentication input src file object from the file choose field
private File get_authen_input_file()
{
String a = this.authen_file_choose_field.getText();
File input_file = new File(a);
return input_file;
}
ActionListener encryp_mode_handler =
new ActionListener() {
public void actionPerformed(ActionEvent e)
{
show_the_panel(((JMenuItem)e.getSource()).getText());
}
};
ActionListener authen_mode_handler =
new ActionListener() {
public void actionPerformed(ActionEvent e)
{
show_the_panel(((JMenuItem)e.getSource()).getText());
}
};
private class RadioButtonHandler implements ItemListener
{
public void itemStateChanged(ItemEvent event)
{
if (event.getSource() == symmetric_button)
{
cipher_combobox.removeAllItems();
cipher_combobox.addItem(cipher_name[0]);
cipher_combobox.addItem(cipher_name[1]);
encryp_mode = GUI_interface.SYMMETRIC_CIPHER;
selected_key_algorithm_name = key_algorithm_name[0];
selected_algorithm_name = algorithm_name[0];
}
else if (event.getSource() == asymmetric_button)
{
cipher_combobox.removeAllItems();
cipher_combobox.addItem(cipher_name[2]);
encryp_mode = GUI_interface.ASYMMETRIC_CIPHER;
selected_key_algorithm_name = key_algorithm_name[2];
selected_algorithm_name = algorithm_name[2];
}
}
}
private class ComboBoxItemHandler implements ItemListener
{
public void itemStateChanged(ItemEvent event)
{
if (cipher_combobox.getSelectedItem() == cipher_combobox.getItemAt(0))
{
encryp_mode = GUI_interface.SYMMETRIC_CIPHER;
selected_key_algorithm_name = key_algorithm_name[0];
selected_algorithm_name = algorithm_name[0];
}
else if (cipher_combobox.getSelectedItem() == cipher_combobox.getItemAt(1))
{
encryp_mode = GUI_interface.SYMMETRIC_CIPHER;
selected_key_algorithm_name = key_algorithm_name[1];
selected_algorithm_name = algorithm_name[1];
}
else if (cipher_combobox.getSelectedItem() == cipher_combobox.getItemAt(2))
{
encryp_mode = GUI_interface.ASYMMETRIC_CIPHER;
selected_key_algorithm_name = key_algorithm_name[2];
selected_algorithm_name = algorithm_name[2];
}
}
}
private class ButtonEventHandler implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
if (event.getSource() == encryp_file_choose_button)
{
File encryp_src_file = select_file();
if (encryp_src_file == null)
{
return;
}
String fileDir = encryp_src_file.getAbsolutePath();
encryp_file_choose_field.setText(fileDir);
}
else if (event.getSource() == authen_file_choose_button)
{
File authen_src_file = select_file();
if (authen_src_file == null)
{
return;
}
String fileDir = authen_src_file.getAbsolutePath();
authen_file_choose_field.setText(fileDir);
}
else if (event.getSource() == encryp_button)
{
if (judge_encryp_input())
{
if (encryp_mode != GUI_interface.MODE_NOT_SET)
{
File encryp_src_file = get_encryp_input_file();
File encryp_dst_file = select_dst_file();
if (encryp_dst_file == null)
{
return;
}
do_encryp(encryp_src_file, encryp_dst_file);
}
else
{
JOptionPane.showMessageDialog(null," 尚未选择加密模式 ! 请选择一种加密算法 .","加密/解密算法",JOptionPane.ERROR_MESSAGE);
return;
}
}
}
else if (event.getSource() == decryp_button)
{
if (judge_encryp_input())
{
if (encryp_mode != GUI_interface.MODE_NOT_SET)
{
File decryp_src_file = get_encryp_input_file();
File decryp_dst_file = select_dst_file();
if (decryp_dst_file == null)
{
return;
}
do_decryp(decryp_src_file, decryp_dst_file);
}
else
{
JOptionPane.showMessageDialog(null," 尚未选择解密模式 ! 请选择一种解密算法 .","加密/解密算法",JOptionPane.ERROR_MESSAGE);
return;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -