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();
|
}
|
}
|
}
|