简体   繁体   English

使用cmd从java swing将参数传递给Keytool

[英]Passing parameters to Keytool from java swing using cmd

I am trying to create a simple user interface for keytool to ease up the certificate generation process. 我正在尝试为keytool创建一个简单的用户界面,以简化证书生成过程。 I am aware that there are better ways to do this and creating a java swing interface is not the optimal solution. 我知道有更好的方法可以做到这一点,创建Java swing接口并不是最佳解决方案。

I am getting the necessary parameters from swing components and pass it to the keytool as follow: 我正在从swing组件获取必要的参数,并将其传递给keytool,如下所示:

try {
    Process p = Runtime
                    .getRuntime()
                    .exec("cmd /c start cmd.exe /K \"keytool.exe &"+command.toString()+" end\"");
} catch (IOException e) {
    e.printStackTrace();
}

Now the problem is after passing the parameters nothing is happening and the cmd shows me the available options in keytool only.(same as entering keytool in cmd) 现在问题出在传递参数之后,什么也没发生,而cmd仅向我显示了keytool中的可用选项(与在cmd中输入keytool相同)

Here you can find the value of command String: 在这里,您可以找到命令字符串的值:

    command.append("keytool -genkey");//hardcoded for now, I'm using this method only
    command.append(" ");
    command.append("-keyalg");
    command.append(" ");
    command.append(algorithm.getSelectedItem()); //comboBox, value RSA/DSA/...
    command.append(" ");
    command.append("-alias");
    command.append(" ");
    command.append(alias.getText());//textfield value signedKey
    command.append(" ");
    command.append("-keystore");
    command.append(" ");
    command.append("selfsigned.jks");//hardcoded for now
    command.append(" ");
    command.append("-validity");
    command.append(" ");
    command.append(validity.getText());//textfield, value 365
    command.append(" ");
    command.append("-keysize");
    command.append(" ");
    command.append(keySize.getText());//depends on selected algorithm, values 2048/1024/...

I am new to keytool and for some reason I really cannot figure out what is wrong here, is it my approach or is it the parameters that I am passing... 我是keytool的新手,由于某种原因,我真的无法弄清楚这里出了什么问题,是我的方法还是我要传递的参数...

PS: sample of command String: keytool -genkey -keyalg RSA -alias signedKey -keystore selfsigned.jks -validity 365 -keysize 2048 PS: 命令字符串示例: keytool -genkey -keyalg RSA -alias signedKey -keystore selfsigned.jks -validity 365 -keysize 2048

The problem was in the String I am using to pass parameter cmd /c start cmd.exe /K "keytool.exe &-genkey -keyalg RSA -alias signedKey -keystore selfsigned.jks -validity 365 -keysize 2048 end" 问题出在我用来传递参数cmd /c start cmd.exe /K "keytool.exe &-genkey -keyalg RSA -alias signedKey -keystore selfsigned.jks -validity 365 -keysize 2048 end"的字符串中cmd /c start cmd.exe /K "keytool.exe &-genkey -keyalg RSA -alias signedKey -keystore selfsigned.jks -validity 365 -keysize 2048 end"

The end makes the problem and once it s been removed it's all good. end产生了问题,一旦将其删除,一切都很好。

Special thanks to Jim Garrison 特别感谢Jim Garrison

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM