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=JCSPRSA
set PROVIDER_CLASS=ru.CryptoPro.JCSP.JCSPRSA
set STORE_TYPE=HDIMAGE
set KEY_PASS=11111111
set KEY_ALIAS="myAes128KeyNoPass"
set COPY_KEY_ALIAS="myAes128KeyCopyNoPass"
set TRUST_STORE=trust_for_jar_signer
set PARAM=-J-Dkeytool.compat=true

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 128 -providername %PROVIDER% -storetype %STORE_TYPE% -keystore NONE -keyalg CP_AES -protected
call "%KEY_TOOL%" %PARAM% -genseckey -alias %KEY_ALIAS% -keysize 128 -providername %PROVIDER% -storetype %STORE_TYPE% -keystore NONE -storepass 1 -keyalg CP_AES -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 echo "Deleting copy-container completed."