I need a php script to generate jks with keystore. What command should I use for it?
exec()
or system()
?
My code:
exec("keytool -genkey -alias 1800 -keyalg RSA -keysize 2048 -validity 365 -keystore 1800.jks -keypass brsacquiro -storepass brsacquiro 2>&1", $return_var);
foreach($return_var as $word)
echo "$word<br>";
I get result:
What is your first and last name?
[Unknown]: What is the name of your organizational unit?
[Unknown]: What is the name of your organization?
[Unknown]: What is the name of your City or Locality?
[Unknown]: What is the name of your State or Province?
[Unknown]: What is the two-letter country code for this unit?
[Unknown]: Is CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown correct?
I get ten of these texts in a row. I need to answer the questions that are listed there. And at the end of this list I get error:
keytool error: java.lang.RuntimeException: Too many retries, program terminated
If I write this command in cmd
, then all is ok.
There's no matter what to use, exec() or system(). Use this sample and replace ClientName, OrganizationUnit etc. with your values
keytool -genkey -noprompt \
-alias alias1 \
-dname "CN=ClientName, OU=OrganizationUnit, O=Organization, L=Locality, S=State, C=CountryCode" \
-keystore keystore \
-storepass password \
-keypass password