使用cmd将参数传递给Java swing中的Keytool(Passing parameters to Keytool from java swing using cmd)

编程入门 行业动态 更新时间:2024-10-28 17:23:43
使用cmd将参数传递给Java swing中的Keytool(Passing parameters to Keytool from java swing using cmd)

我正在尝试为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

更多推荐

本文发布于:2023-07-16 02:47:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1122720.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   swing   Java   cmd   parameters

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!