echo off

set KEY_TOOL_JRE=C:\Program Files\Java\jdk1.8.0_301\jre
set KEY_TOOL=%KEY_TOOL_JRE%\bin\keytool.exe
set PROVIDER=JCSP
set PROVIDER_CLASS=ru.CryptoPro.JCSP.JCSP
set PROVIDER_PATH=C:\signed\JCSP.jar
set STORE_TYPE=HDIMAGE
set KEY_PASS=11111111
REM GOST28147 GOST3412_2015_M GOST3412_2015_K
set ALG=GOST28147
set KEY_ALIAS="my%ALG%NoPass"
set COPY_KEY_ALIAS="my%ALG%CopyNoPass"
set TRUST_STORE=trust_for_jar_signer
set PARAM=-J-Dkeytool.compat=true
REM -J-Djava.security.debug=all

echo "1. List containers:"
call "%KEY_TOOL%" %PARAM% -list -providername %PROVIDER% -storetype %STORE_TYPE% -keystore NONE -storepass 1
echo "Listing completed."

pause

echo "1*. Control deleting container:"
call "%KEY_TOOL%" %PARAM% -delete -alias %KEY_ALIAS% -providername %PROVIDER% -storetype %STORE_TYPE% -keystore NONE -storepass 1
echo "Control deleting completed."

pause

echo "1**. Control deleting copy-container:"
call "%KEY_TOOL%" %PARAM% -delete -alias %COPY_KEY_ALIAS% -providername %PROVIDER% -storetype %STORE_TYPE% -keystore NONE -storepass 1
echo "Control deleting completed."

pause

echo "2. Generating key:"
REM call "%KEY_TOOL%" %PARAM% -genseckey -alias %KEY_ALIAS% -keysize 256 -providername %PROVIDER% -storetype %STORE_TYPE% -keystore NONE -keyalg %ALG% -protected
call "%KEY_TOOL%" %PARAM% -genseckey -alias %KEY_ALIAS% -keysize 256 -providername %PROVIDER% -storetype %STORE_TYPE% -keystore NONE -storepass 1 -keyalg %ALG% -keypass %KEY_PASS%
echo "Generating secret key completed."

pause

echo "3. Copy container:"
REM call "%KEY_TOOL%" %PARAM% -importkeystore -srcprotected -srckeystore %TRUST_STORE% -srcstoretype %STORE_TYPE% -destkeystore NONE -deststoretype %STORE_TYPE% -deststorepass 1 -srcprovidername %PROVIDER% -destprovidername %PROVIDER% -srcalias %KEY_ALIAS% -destalias %COPY_KEY_ALIAS%
call "%KEY_TOOL%" %PARAM% -importkeystore -srckeystore %TRUST_STORE% -srcstoretype %STORE_TYPE% -srcstorepass %KEY_PASS% -destkeystore NONE -deststoretype %STORE_TYPE% -deststorepass 1 -srcprovidername %PROVIDER% -destprovidername %PROVIDER% -srcalias %KEY_ALIAS% -destalias %COPY_KEY_ALIAS%
echo "Copying completed."

pause

REM echo "4. Deleting container:"
REM call "%KEY_TOOL%" %PARAM% -delete -alias %KEY_ALIAS% -providername %PROVIDER% -storetype %STORE_TYPE% -keystore NONE -storepass 1
REM echo "Deleting container completed."

REM pause

REM echo "5. Deleting copy-container:"
REM call "%KEY_TOOL%" %PARAM% -delete -alias %COPY_KEY_ALIAS% -providername %PROVIDER% -storetype %STORE_TYPE% -keystore NONE -storepass 1
REM secho "Deleting copy-container completed."