You get the error because, for the -inkey
argument, you have to specify a private key; not a public key.
OpenSSL's pkcs12 command doesn't provide a way to consolidate public and private keys into a single file. It is specifically used to consolidate certificates and private keys into a single file. In the above case, what you have is a public key, not a certificate.
From the man page:
-in filename
The filename to read certificates and private keys from, standard input by default. They must all be in PEM format. The order doesn't matter but one private key and its corresponding certificate should be present. If additional certificates are present they will also be included in the PKCS#12 file.
Note that it specifically mentions that one private key and its corresponding certificate should be present. The command that I typically use to generate a PKCS#12 file is:
openssl pkcs12 -export -in cert.pem -inkey private.key -out file.pfx -name "My Certificate"