-1

I'm trying to create a batch file to generate a certificate using java keytool. the workflow is as:

keytool -genkey -alias test -storetype PKCS12 -keyalg RSA -keysize 2048 -keystore keystore.p12 -validity 3650

After you hit enter, it's followed by a bunch of questions:

Enter keystore password:

Re-enter new password:

What is your first and last name? [Unknown]: What is the name of your organizational unit?

What is the name of your organization?

What is the name of your City or Locality?

What is the name of your State or Province?

What is the two-letter country code for this unit?

Is CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown correct?

those answers will be gathered in advance. I want to automatically put answers to those prompts and generate the certificate.

I found something like "echo {answer} | {batch command}" but I don't know how to apply it in this use case because it's multiple answers.

Squashman
  • 13,649
  • 5
  • 27
  • 36
Dong Hang
  • 9
  • 5

1 Answers1

1
( echo password
echo password
echo Hang
echo Dong
... etc...
) | keytool -genkey ...

should work (depends on how the utility is programmed)
Be sure to not include any stray spaces

Stephan
  • 53,940
  • 10
  • 58
  • 91