whycrzg
2021-03-11 a2bbdc9501439ec20cadd8f1efbee1a0ac8cf3d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
 * 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));
                        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
}