我正在尝试为keytool创建一个简单的用户界面,以简化证书生成过程。 我知道有更好的方法来做到这一点,创建一个java swing接口并不是最佳解决方案。
我从swing组件中获取必要的参数并将其传递给keytool,如下所示:
try { Process p = Runtime .getRuntime() .exec("cmd /c start cmd.exe /K \"keytool.exe &"+command.toString()+" end\""); } catch (IOException e) { e.printStackTrace(); }现在的问题是在传递参数后没有发生任何事情,cmd只显示了keytool中的可用选项。(与在cmd中输入keytool相同)
在这里你可以找到命令 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/...我是keytool的新手,由于某些原因,我真的无法弄清楚这里有什么问题,是我的方法还是我传递的参数......
PS: 命令示例字符串: keytool -genkey -keyalg RSA -alias signedKey -keystore selfsigned.jks -validity 365 -keysize 2048
I am trying to create a simple user interface for keytool to ease up the certificate generation process. I am aware that there are better ways to do this and creating a java swing interface is not the optimal solution.
I am getting the necessary parameters from swing components and pass it to the keytool as follow:
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)
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...
P.S: sample of command String: keytool -genkey -keyalg RSA -alias signedKey -keystore selfsigned.jks -validity 365 -keysize 2048
最满意答案
问题出在我用来传递参数的字符串cmd /c start cmd.exe /K "keytool.exe &-genkey -keyalg RSA -alias signedKey -keystore selfsigned.jks -validity 365 -keysize 2048 end"
end产生了问题,一旦它被删除,一切都很好。
特别感谢Jim Garrison
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"
The end makes the problem and once it s been removed it's all good.
Special thanks to Jim Garrison
更多推荐
发布评论