/* * Created by JFormDesigner on Mon Nov 30 11:13:07 CST 2020 */ package org.pzone.crypto; import java.awt.*; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.Transferable; import java.awt.event.*; import java.math.BigInteger; import javax.swing.*; import org.bouncycastle.math.ec.ECPoint; /** * @author abc generate */ public class RegistCode extends JFrame { /** * */ private static final long serialVersionUID = -5784472186750311791L; public RegistCode() { initComponents(); initsetting(); } private void initsetting() { textField_regeditCode.setLineWrap(true); // 激活自动换行功能 textField_regeditCode.setWrapStyleWord(true); // 激活断行不断字功能 } /** * 获取到的duration信息为凭证有效时长,单位为天;永久凭证duration为-1 * @param e */ private void button_generateActionPerformed(ActionEvent e) { String srcmachineCode = textField_machineCode.getText().trim(); String duration = textField_duration.getText().trim(); //机器码+时间戳+有效时长 产生唯一的注册码 if(srcmachineCode.length()>0){ String finalSrcmachineCode = srcmachineCode; new Thread(new Runnable() { @Override public void run() { try { SM2 x = new SM2(); x.setDebug(true); BigInteger privKey = x.importPrivateKey("pri_key.ksm"); ECPoint pubKey = x.importPublicKey("pub_key.ksm"); byte[] machineCode = ByteConvertUtil.hexToByteArray(finalSrcmachineCode); String dCode = x.decrypt(machineCode, privKey);// 解密后机器 码 String tempStr = System.currentTimeMillis()+"machineCode:"+dCode + "@@" + "Company: Fuguang Electronic\n" + "Project:BTS monitor platform\n" + "Licence duration:"+duration; byte[] endata = x.encrypt(tempStr, pubKey);// 注册码 显示 String bytesToHexString = ByteConvertUtil.bytesToHexString(endata); textField_regeditCode.setText(bytesToHexString); } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, "该激活码不可用"); } } }).start(); } } private void button_exitActionPerformed(ActionEvent e) { dispose(); } private void button_copyActionPerformed(ActionEvent e) { String regeditCode = textField_regeditCode.getText(); // 获取系统剪贴板 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); // 封装文本内容 Transferable trans = new StringSelection(regeditCode); // 把文本内容设置到系统剪贴板 clipboard.setContents(trans, null); } private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY // //GEN-BEGIN:initComponents panel9 = new JPanel(); panel5 = new JPanel(); panel2 = new JPanel(); label2 = new JLabel(); scrollPane1 = new JScrollPane(); textField_regeditCode = new JTextArea(); panel3 = new JPanel(); panel4 = new JPanel(); button_copy = new JButton(); button_exit = new JButton(); panel11 = new JPanel(); panel1 = new JPanel(); label1 = new JLabel(); textField_machineCode = new JTextField(); panel10 = new JPanel(); button_generate = new JButton(); panel12 = new JPanel(); label3 = new JLabel(); textField_duration = new JTextField(); panel13 = new JPanel(); button_generate2 = new JLabel(); panel6 = new JPanel(); panel7 = new JPanel(); panel8 = new JPanel(); //======== this ======== setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setResizable(false); setMinimumSize(new Dimension(500, 330)); Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); //======== panel9 ======== { panel9.setPreferredSize(new Dimension(20, 0)); panel9.setLayout(new BorderLayout()); } contentPane.add(panel9, BorderLayout.EAST); //======== panel5 ======== { panel5.setLayout(new BorderLayout(10, 10)); //======== panel2 ======== { panel2.setAlignmentY(20.0F); panel2.setLayout(new BorderLayout()); //---- label2 ---- label2.setText("\u6ce8\u518c\u7801"); label2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 14)); panel2.add(label2, BorderLayout.WEST); //======== scrollPane1 ======== { //---- textField_regeditCode ---- textField_regeditCode.setAutoscrolls(false); scrollPane1.setViewportView(textField_regeditCode); } panel2.add(scrollPane1, BorderLayout.CENTER); } panel5.add(panel2, BorderLayout.CENTER); //======== panel3 ======== { panel3.setAlignmentY(20.0F); panel3.setPreferredSize(new Dimension(148, 40)); panel3.setLayout(new BorderLayout()); //======== panel4 ======== { panel4.setLayout(new GridLayout(1, 0, 10, 0)); //---- button_copy ---- button_copy.setText("\u590d\u5236"); button_copy.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16)); button_copy.addActionListener(e -> button_copyActionPerformed(e)); panel4.add(button_copy); //---- button_exit ---- button_exit.setText("\u9000\u51fa"); button_exit.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16)); button_exit.addActionListener(e -> button_exitActionPerformed(e)); panel4.add(button_exit); } panel3.add(panel4, BorderLayout.EAST); } panel5.add(panel3, BorderLayout.SOUTH); //======== panel11 ======== { panel11.setLayout(new GridLayout(2, 0, 0, 1)); //======== panel1 ======== { panel1.setMinimumSize(new Dimension(194, 33)); panel1.setPreferredSize(new Dimension(194, 33)); panel1.setLayout(new BorderLayout()); //---- label1 ---- label1.setText("\u673a\u5668\u7801"); label1.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 14)); panel1.add(label1, BorderLayout.WEST); panel1.add(textField_machineCode, BorderLayout.CENTER); //======== panel10 ======== { panel10.setLayout(new BorderLayout()); //---- button_generate ---- button_generate.setText("\u751f\u6210"); button_generate.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16)); button_generate.addActionListener(e -> button_generateActionPerformed(e)); panel10.add(button_generate, BorderLayout.WEST); } panel1.add(panel10, BorderLayout.EAST); } panel11.add(panel1); //======== panel12 ======== { panel12.setMinimumSize(new Dimension(194, 33)); panel12.setPreferredSize(new Dimension(194, 33)); panel12.setLayout(new BorderLayout()); //---- label3 ---- label3.setText("\u6709\u6548\u671f"); label3.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 14)); panel12.add(label3, BorderLayout.WEST); panel12.add(textField_duration, BorderLayout.CENTER); //======== panel13 ======== { panel13.setLayout(new BorderLayout()); //---- button_generate2 ---- button_generate2.setText(" \u5929,-1\u4e3a\u6c38\u4e45"); button_generate2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 16)); button_generate2.setPreferredSize(new Dimension(100, 22)); button_generate2.setMaximumSize(new Dimension(120, 22)); panel13.add(button_generate2, BorderLayout.WEST); } panel12.add(panel13, BorderLayout.EAST); } panel11.add(panel12); } panel5.add(panel11, BorderLayout.NORTH); } contentPane.add(panel5, BorderLayout.CENTER); //======== panel6 ======== { panel6.setPreferredSize(new Dimension(0, 20)); panel6.setLayout(new BorderLayout()); } contentPane.add(panel6, BorderLayout.SOUTH); //======== panel7 ======== { panel7.setPreferredSize(new Dimension(0, 20)); panel7.setLayout(new BorderLayout()); } contentPane.add(panel7, BorderLayout.NORTH); //======== panel8 ======== { panel8.setPreferredSize(new Dimension(20, 0)); panel8.setLayout(new BorderLayout()); } contentPane.add(panel8, BorderLayout.WEST); pack(); setLocationRelativeTo(getOwner()); // //GEN-END:initComponents } // JFormDesigner - Variables declaration - DO NOT MODIFY // //GEN-BEGIN:variables private JPanel panel9; private JPanel panel5; private JPanel panel2; private JLabel label2; private JScrollPane scrollPane1; private JTextArea textField_regeditCode; private JPanel panel3; private JPanel panel4; private JButton button_copy; private JButton button_exit; private JPanel panel11; private JPanel panel1; private JLabel label1; private JTextField textField_machineCode; private JPanel panel10; private JButton button_generate; private JPanel panel12; private JLabel label3; private JTextField textField_duration; private JPanel panel13; private JLabel button_generate2; private JPanel panel6; private JPanel panel7; private JPanel panel8; // JFormDesigner - End of variables declaration //GEN-END:variables }