yangys
2025-05-26 2ba2c339acf41fd7bb2a49f0ce186fd664a80cb5
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
package com.qianwen.license.keygen;
 
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collection;
 
import org.junit.jupiter.api.Test;
import org.mockito.internal.util.io.IOUtil;
 
import cn.hutool.core.util.RuntimeUtil;
 
public class GenUtilTest {
 
    //@Test
    public void genKeyPair() {
        try {
            GenUtil.genKeyPair("privateKeys.store");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    
    //@Test
    public void exportCert() {
        try {
            GenUtil.exportCert("privateKeys.store");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    //@Test
    public void importCertToPublicStore() {
        try {
            GenUtil.importCertToPublicStore("publicCerts.store");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    //@Test
    public void t() {
        try {
            String cmd = "cmd.exe /c echo y | keytool -import -alias publiccert -file d:/cert/certfile.cer -keystore d:/cert/publicCerts.store -storepass a1b2c3";
            String str = RuntimeUtil.execForStr(cmd.toString());
         
            System.out.println(str);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    @Test
    public void t2() {
        try {
            String cmd = "keytool -import -alias publiccert -file d:/cert/certfile.cer -keystore d:/cert/publicCerts.store -storepass a1b2c3";
            
            
            Process proc = RuntimeUtil.exec(cmd.toString());
            
            InputStream ins = proc.getInputStream();
            byte[] buffer = new byte[ins.available()];
            int readLen = ins.read(buffer);
            String s = new String(buffer,"GBK");
            System.out.println(s);
 
           
            try(OutputStream os = proc.getOutputStream()){
                os.write("y".getBytes());
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}