java 在批处理文件中回答 keytool 的密码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7571949/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 20:33:38  来源:igfitidea点击:

Answer password to keytool in batch files

javasecuritybatch-fileappletkeytool

提问by ZenfStor

i need use keytool and jarsigner to sign a lot o files here in many folders.
Each time i start sign theses files i need delete the .cert and keystore file to recreate it.
Im on development enviroment and using fake passwd to sign it, after application working the infra people will take care of sign it, i havent access to real certificates.
When i was typing and the keytool -import .......,after enter, ask for password i simply type it but in batch it become a problem.
Im on windows 7 here.
I was tried keytool -import ....... < passHereand keytool -import ....... | passHere, too but it doesn't work.
I want turn sign most automatic possible.
There is someone telling about use it programatically herebut i simply need it on a bat file.
The password is a fixedvalue insidebatch file.
There is a way to give passwd inline to keytool?
Is possible set an enviroment variable in 'run time' to feed keytool password? how do it ?
There is a way to give passwd inside bath to keytool? I see thisbut dont help because i'm not a asm developer and not sure if it match problem and im wondering if there is something more simple.

我需要使用 keytool 和 jarsigner 在许多文件夹中签署很多 o 文件。
每次我开始签署这些文件时,我都需要删除 .cert 和密钥库文件来重新创建它。
我在开发环境中并使用假密码对其进行签名,在应用程序工作后,基础设施人员将负责签名,我无法访问真正的证书。
当我输入时keytool -import .......,输入后询问密码我只是输入它,但批量输入它就成了一个问题。
我在这里使用 Windows 7。
我试过keytool -import ....... < passHerekeytool -import ....... | passHere,太多,但它不工作。
我想要最自动的转向标志。
有人说在这里以编程方式使用它但我只需要在 bat 文件中使用它。
密码是一个固定批处理文件。
有没有办法将 passwd 内联到 keytool?
是否可以在“运行时”中设置环境变量来提供 keytool 密码?怎么办?
有没有办法将浴缸内的密码提供给keytool?我看到了这一点,但没有帮助,因为我不是 asm 开发人员,不确定它是否匹配问题,我想知道是否有更简单的东西。

Thanks

谢谢

回答by hellerpop

This command works for me (tested it with keytool from jdk 1.6.0.24):

这个命令对我有用(用 jdk 1.6.0.24 的 keytool 测试过):

keytool -import -noprompt -file PathToCertificate -alias SomeCertificateAlias -keystore PathToKeyStore -storepass KeyStorePassword

回答by Bruce Becker

I needed batch creation of a keystore since I don't have access to the remote machine and need to create the keystore automatically. I tried this command (with the -nopromptand -storepassoptions), but it still asked for a password. I got around this doing an echo <password> | keytool ...with the same options as the other answer, which worked.

我需要批量创建密钥库,因为我无权访问远程机器并且需要自动创建密钥库。我尝试了这个命令(使用-noprompt-storepass选项),但它仍然要求输入密码。我解决了这个问题,echo <password> | keytool ...使用了与其他答案相同的选项,这很有效。

回答by wowbagger

I needed to create JKS keystores with keys from a PKCS12 store.

我需要使用来自 PKCS12 存储的密钥创建 JKS 密钥存储。

This worked for me:

这对我有用:

echo <passphrase>| keytool.exe -importkeystore -srckeystore <source_pkcs12> -srcstoretype pkcs12 -destkeystore <jks_store> -deststoretype JKS -storepass <store_passphrase> -noprompt

The trick was to not have a space between the passphrase and the | pipe symbol, otherwise keytool considers the space part of the passphrase.

诀窍是在密码短语和 | 之间没有空格。管道符号,否则 keytool 会考虑密码的空格部分。