Generate a Test Key

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout testkey.key -out testkey.crt

Informations about the used arguments from the OpenSSL man page:

Now you can pack the key into a PKCS#12 container:

openssl pkcs12 -export -out testkey.p12 -inkey testkey.key -in testkey.crt

Informations about the used arguments from the OpenSSL man page: