📄 framecpro.java
字号:
package cproissue;
import java.awt.*;
import javax.swing.*;
import java.awt.BorderLayout;
import java.io.*;
import java.util.Enumeration;
import java.lang.reflect.Method;
import java.io.*;
import java.security.*;
import java.security.cert.Certificate;
import java.util.Date;
import java.math.*;
import sun.security.x509.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.awt.event.*;
import java.awt.Font;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.ResultSet;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class FrameCPro extends JFrame {
JLabel jLabel1 = new JLabel();
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JLabel jLabel7 = new JLabel();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JTextField cnText = new JTextField();
JTextField ouText = new JTextField();
JTextField oText = new JTextField();
JTextField lText = new JTextField();
JTextField stText = new JTextField();
JTextField cText = new JTextField();
JLabel jLabel8 = new JLabel();
CertEntity ce;
javax.swing.JButton jButton3 = new JButton();
javax.swing.JLabel jinggao = new JLabel();
JLabel jLabel9 = new JLabel();
JPasswordField cpass = new JPasswordField();
JPasswordField cpassok = new JPasswordField();
public FrameCPro() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
public FrameCPro(CertEntity ce1) {
try {
jbInit();
this.ce=ce1;
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(xYLayout1);
this.setTitle("申请证书");
jLabel1.setForeground(Color.black);
jLabel1.setText("第一步:生成自签证书,请输入以下信息:");
jButton1.addActionListener(new FrameCPro_jButton1_actionAdapter(this));
this.setJMenuBar(null);
jLabel8.setText("请输入私钥保护密码:(8位)");
jButton2.setText("取消");
jButton2.addActionListener(new FrameCPro_jButton2_actionAdapter(this));
jButton1.setText("下一步");
jLabel7.setText("国家");
jLabel6.setText("省市");
jLabel5.setText("县市");
jLabel4.setText("单位");
jLabel3.setText("部门");
jButton3.setFont(new java.awt.Font("仿宋_GB2312", Font.PLAIN, 12));
jButton3.setForeground(Color.red);
jButton3.setText("检测别名");
jButton3.addActionListener(new FrameCPro_jButton3_actionAdapter(this));
jinggao.setForeground(Color.red);
jinggao.setVisible(true);
jLabel9.setText("再次确认密码:");
this.getContentPane().add(jLabel1, new XYConstraints(2, 9, 233, -1));
this.getContentPane().add(jLabel2, new XYConstraints(36, 36, -1, -1));
this.getContentPane().add(jLabel3, new XYConstraints(205, 35, -1, -1));
this.getContentPane().add(jButton3, new XYConstraints(15, 61, 84, 24));
this.getContentPane().add(jinggao, new XYConstraints(106, 64, 170, 19));
this.getContentPane().add(jLabel4, new XYConstraints(38, 95, -1, -1));
this.getContentPane().add(jLabel5, new XYConstraints(208, 90, -1, -1));
this.getContentPane().add(jLabel6, new XYConstraints(37, 140, -1, -1));
this.getContentPane().add(stText, new XYConstraints(96, 137, 79, -1));
this.getContentPane().add(oText, new XYConstraints(96, 88, 79, -1));
this.getContentPane().add(jLabel7, new XYConstraints(209, 138, -1, -1));
this.getContentPane().add(lText, new XYConstraints(267, 88, 78, -1));
this.getContentPane().add(jLabel8, new XYConstraints(36, 175, -1, -1));
this.getContentPane().add(jLabel9, new XYConstraints(63, 206, 121, -1));
this.getContentPane().add(cnText, new XYConstraints(92, 35, 83, -1));
this.getContentPane().add(ouText, new XYConstraints(266, 34, 79, -1));
this.getContentPane().add(cText, new XYConstraints(267, 137, 78, -1));
this.getContentPane().add(jButton1, new XYConstraints(94, 245, 74, -1));
this.getContentPane().add(jButton2, new XYConstraints(242, 245, 72, -1));
this.getContentPane().add(cpassok, new XYConstraints(206, 203, 123, 21));
this.getContentPane().add(cpass, new XYConstraints(206, 177, 124, 21));
jLabel2.setText("别名");
}
//检测别名
public void jButton3_actionPerformed(ActionEvent actionEvent) {
try{
String pass=""+ce.stroepass+"";
String name="mykeystore";
boolean temp=false;
FileInputStream in=new FileInputStream(name);
KeyStore ks=KeyStore.getInstance("JKS");
ks.load(in,pass.toCharArray());
Enumeration e=ks.aliases( );
while( e.hasMoreElements())
{
if(e.nextElement().toString().equals(cnText.getText()+"_signed"))
{
temp=true;
break;
}
}
if(temp)
jinggao.setText("此别名已经存在!请重新输入。");
else
jinggao.setText("此别名可以使用,请继续。");
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}
//第一步
public void jButton1_actionPerformed(ActionEvent e) {
try
{
if(new String(cpass.getPassword()).equals(new String(cpassok.getPassword())))
{
//根据主题信息产生待签名证书
String ss = "keytool -genkey -dname \"CN=" + cnText.getText() +
",OU=" +
ouText.getText() + ",O=" + oText.getText() + ",L=" +
lText.getText() + ", ST=" + stText.getText() +
", C=" +
cText.getText() + "\" -alias " + cnText.getText() +
" -keyalg RSA -keysize 1024 -keystore mykeystore -keypass " +
new String(cpass.getPassword()) + " -storepass " +
ce.stroepass + " -validity 3500";
String cmd = "cmd /E:ON /c start " + ss;
Runtime.getRuntime().exec(cmd);
//获得公有变量的值
ce.cuser = cnText.getText();
ce.cpass = new String(cpass.getPassword());
ce.cn = cnText.getText();
ce.ou = ouText.getText();
ce.o = oText.getText();
ce.l = lText.getText();
ce.st = stText.getText();
ce.c = cText.getText();
//进入第二步
FrameCPDown cpd = new FrameCPDown(ce);
cpd.setSize(400, 350);
cpd.setLocation(312, 234);
cpd.setVisible(true);
this.dispose();
}
else
{
jinggao.setText("密码前后不一致,重输!");
}
}
catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
//返回主界面
public void jButton2_actionPerformed(ActionEvent e) {
this.dispose();
}
}
class FrameCPro_jButton3_actionAdapter implements ActionListener {
private FrameCPro adaptee;
FrameCPro_jButton3_actionAdapter(FrameCPro adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent actionEvent) {
adaptee.jButton3_actionPerformed(actionEvent);
}
}
class FrameCPro_jButton2_actionAdapter implements ActionListener {
private FrameCPro adaptee;
FrameCPro_jButton2_actionAdapter(FrameCPro adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
class FrameCPro_jButton1_actionAdapter implements ActionListener {
private FrameCPro adaptee;
FrameCPro_jButton1_actionAdapter(FrameCPro adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -