@echo off

set key_name=agent
set key_passphrase=JobScheduler
set key_type=ECDSA

if "%key_type%" == "ECDSA" (
    @rem create private key in pkcs1 format
    @rem   without passphrase
    openssl ecparam -name secp256k1 -genkey -noout -out %key_name%.key
    @rem   with passphrase
    @rem openssl ecparam -genkey -name secp256k1 | openssl ec -aes256 -passout pass:"%key_passphrase%" -out %key_name%.key

    @rem create certificate
    openssl req -new -x509 -key %key_name%.key -out %key_name%.crt -days 1825

    @rem extract public key from private key
    @rem openssl ec -in %key_name%.key -passin pass:"%key_passphrase%" -pubout > %key_name%.pub
) else (
    @rem create private key in pkcs1 format
    @rem  without passphrase
    openssl req -x509 -sha256 -newkey rsa:2048 -keyout %key_name%.key -out %key_name%.crt
    @rem  with passphrase
    @rem  openssl req -x509 -sha256 -newkey rsa:2048 -passout pass:"%key_passphrase%" -keyout %key_name%.key -out %key_name%.crt

    @rem extract public key from certificate
    @rem openssl x509 -pubkey -noout -in %key_name%.crt > %key_name%.pub
)

