Friday, August 04, 2006

Generate Self signed Java JKS Keystore using input from Batch file

Here is a batch file used to create your self signed Java keystore for SSL

Often you encounter a situation where a BATCH file, much the same as a shell script, will do the job as your installer or configuration tool.


@echo off
cls
echo SSL Certificate Generator
echo.

SET /P MACHINE_NAME=Enter machine name or Q(Quit)

IF %MACHINE_NAME%==q goto end
IF %MACHINE_NAME%==Q goto end

echo Generating certificate for machine %MACHINE_NAME%

keytool -genkey -alias %MACHINE_NAME% -dname "CN=%MACHINE_NAME%, OU=OpenLogbooks, O=OpenLogbooks, L=Lichfield, S=Staffordshire, C=UK" -keyalg RSA -keypass password -storepass password -keystore mykeystore.keystore
keytool -export -alias %MACHINE_NAME% -storepass password -file mykeystore.server.crt -keystore mykeystore.keystore

:end