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

📄 framequery.java

📁 数字证书注册和签发系统
💻 JAVA
字号:
package cproissue;

import java.awt.*;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.security.PrivateKey;
import java.io.ObjectOutputStream;
import java.security.Key;
import java.io.FileInputStream;
import java.security.KeyStore;
import javax.crypto.SecretKeyFactory;
import javax.crypto.Cipher;
import java.io.FileOutputStream;
import javax.crypto.spec.DESedeKeySpec;
import com.borland.jbcl.layout.*;
import java.nio.*;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class FrameQuery extends JFrame {
    XYLayout xYLayout1 = new XYLayout();
    JLabel jLabel1 = new JLabel();
    JTextField nameText = new JTextField();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    JLabel jLabel2 = new JLabel();
    JLabel jLabel3 = new JLabel();
    CertEntity ce;
    JLabel messText = new JLabel();
  JPasswordField kouling = new JPasswordField();
    public FrameQuery() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
    public FrameQuery(CertEntity ce) {
        try {
            jbInit();
            this.ce=ce;
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }


    private void jbInit() throws Exception {
        getContentPane().setLayout(xYLayout1);
        this.setTitle("重新生成私钥");
        jLabel1.setText("请输入证书的别名:");
        jButton1.setText("确定");
        jButton1.addActionListener(new FrameQuery_jButton1_actionAdapter(this));
        jButton2.setText("返回");
        jButton2.addActionListener(new FrameQuery_jButton2_actionAdapter(this));
        jLabel2.setText("请输入证书的私钥保护密码:");
        jLabel3.setForeground(Color.red);
        jLabel3.setText("(8位)");
        messText.setForeground(Color.red);
        messText.setText("别名与私钥保护密码不匹配,请重新输入!");
        messText.setVisible(false);
    kouling.setText("");
    this.getContentPane().add(nameText,
                                  new XYConstraints(213, 53, 106, -1));
        this.getContentPane().add(jLabel1, new XYConstraints(63, 54, -1, -1));
        this.getContentPane().add(jLabel2, new XYConstraints(36, 108, -1, -1));
        this.getContentPane().add(jLabel3, new XYConstraints(324, 107, -1, -1));
        this.getContentPane().add(jButton1, new XYConstraints(79, 181, 73, -1));
        this.getContentPane().add(messText, new XYConstraints(83, 146, -1, -1));
        this.getContentPane().add(jButton2, new XYConstraints(229, 181, 76, -1));
        this.getContentPane().add(kouling, new XYConstraints(212, 106, 108, 22));
    }

    public void jButton1_actionPerformed(ActionEvent e) {
        try{
        //从密钥库读取此用户证书的私钥
           FileInputStream inn=new FileInputStream("mykeystore");
           KeyStore ks1=KeyStore.getInstance("JKS");
           ks1.load(inn,ce.stroepass.toCharArray());
           java.security.cert.Certificate cn=ks1.getCertificate(nameText.getText());
           PrivateKey prk=(PrivateKey)ks1.getKey(nameText.getText(),kouling.getPassword());
           inn.close();
           String fileIni=nameText.getText()+"_privkeySSS.dat";
           //写未加密的私钥
           FileOutputStream  f=new FileOutputStream(fileIni);
           ObjectOutputStream b=new  ObjectOutputStream(f);
           b.writeObject(prk);
           b.close();
           int i;
           //转化待加密的私钥
           FileInputStream fis=new FileInputStream(fileIni);
           byte[] keyFirst=new byte[fis.available()];
           fis.read(keyFirst);
           fis.close();
           String s=prk.toString();
           byte ptext[]=s.getBytes("UTF8");
           //得到私钥保护密码做为DES加密密钥
           byte[] passwd=((new String(kouling.getPassword())+"0000000000000000")).getBytes();
           DESedeKeySpec pbks=new DESedeKeySpec(passwd);
           SecretKeyFactory kf=SecretKeyFactory.getInstance("DESede");
           Key k=kf.generateSecret(pbks);
           //初始化密钥器
           Cipher cp=Cipher.getInstance("DESede");
           cp.init(Cipher.ENCRYPT_MODE, k);
           //第一次加密
           byte ctext1[]=cp.doFinal(keyFirst);
           //第二次加密
           byte ctext2[]=cp.doFinal(ctext1);
           //写文件
           FileOutputStream f2=new FileOutputStream(nameText.getText()+"_privkey.dat");
           ByteBuffer bf=ByteBuffer.allocate(2);
           short sm=(short)ctext1.length;
           bf.putShort(sm);
           byte[] bt=bf.array();
           ByteBuffer bf1=ByteBuffer.allocate(2);
           short sm1=(short)ctext2.length;
           bf1.putShort(sm1);
           byte[] bt1=bf1.array();

         /*  ByteBuffer bf1=ByteBuffer.allocate(2);
           bf1.put(bt);
           short s2=bf1.getShort();*/
           f2.write(bt);
           f2.write(bt1);
           f2.write("0".getBytes("UTF8"));
           f2.write(" ".getBytes("UTF8"));
           f2.write(" ".getBytes("UTF8"));
           f2.write(" ".getBytes("UTF8"));

           f2.write(ctext1);
           f2.write(ctext2);
           //下一步
           FrameQDown qd=new FrameQDown();
           qd.setSize(400,350);
           qd.setLocation(312,234);
           qd.setVisible(true);
           qd.lable1.setText("恭喜您,私钥已经重新产生!");
           qd.lable1.setVisible(true);
           this.dispose();
       }
       catch(Exception ex)
        {
           messText.setVisible(true);
        }
    }
    public void jButton2_actionPerformed(ActionEvent e) {
        this.dispose();
    }
}


class FrameQuery_jButton2_actionAdapter implements ActionListener {
    private FrameQuery adaptee;
    FrameQuery_jButton2_actionAdapter(FrameQuery adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton2_actionPerformed(e);
    }
}


class FrameQuery_jButton1_actionAdapter implements ActionListener {
    private FrameQuery adaptee;
    FrameQuery_jButton1_actionAdapter(FrameQuery adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
    }
}

⌨️ 快捷键说明

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