Answer password to keytool in batch files
Asked Answered
C

3

15

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 ....... < passHere and keytool -import ....... | passHere, too but it doesn't work.
I want turn sign most automatic possible.
There is someone telling about use it programatically here but i simply need it on a bat file.
The password is a fixed value inside batch 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 this but 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.

Thanks

Calamint answered 27/9, 2011 at 15:46 Comment(2)
your requirement more or less subverts the entire point of keytool.Saporific
@mcfinnigan, why? im on development enviroment and fake key having a lot of headache to put applet to work. Left infra people take care of real sign after application running ok. By the way, there is some way ? Thanks.Calamint
B
30

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

keytool -import -noprompt -file PathToCertificate -alias SomeCertificateAlias -keystore PathToKeyStore -storepass KeyStorePassword
Bohrer answered 29/10, 2012 at 16:50 Comment(0)
U
1

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 -noprompt and -storepass options), 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.

Unpracticed answered 28/6, 2015 at 10:37 Comment(1)
can you show me an example of the line you entered please?Estevan
K
1

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

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.

Kannan answered 4/10, 2019 at 8:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.