echo off

set KEY_TOOL_JRE=C:\Program Files\Java\jdk1.8.0_111\jre
set KEY_TOOL=%KEY_TOOL_JRE%\bin\keytool.exe
set PROVIDER=JCSPRSA
set PROVIDER_PATH=C:\currentRel\CryptoProJCP\forTest\JCSP.jar
set PROVIDER_CLASS=ru.CryptoPro.JCSP.JCSPRSA
set STORE_TYPE=HDIMAGE
set KEY_PASS=11111111
set KEY_ALIAS="my3DESKey"
set COPY_KEY_ALIAS="my3DESKeyCopy"
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% -providerpath %PROVIDER_PATH% -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% -providerpath %PROVIDER_PATH% -storetype %STORE_TYPE% -keystore NONE -storepass 1
echo "Control deleting completed."

pause

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

pause

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

pause

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

pause

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