是否可以将JSON私钥转换为PKCS12格式?

I am working with Google Cloud Storage services in PHP, I have a APPLICATION_GOOGLE_CLIENT_KEY_FILE in JSON format.

My question is can we convert JSON private key into PKCS12 format? If yes then please provide me some way, as I am unable to do so.

Here's what I pieced together for a similar situation from the openssl docs. It isn't based on any deep understanding of keys, but it did work for me for the libraries I was using with Node. In the object from the JSON file, there is a member called 'private_key'. Copy its value into a new file, say 'jsonkey.key', and replace all the occurrences ' ' with actual newlines. Then run the command:

openssl rsa -in jsonkey.key | openssl pkcs12 -password pass:notasecret -export -nocerts -out p12key.p12

Of course, change p12key.p12 to whatever you want your pkcs12 file to be called.

This builds on Holy Joe's answer using a quick and dirty shell script. You'll need node to be installed.

#!/bin/sh
value=`cat ./json.json`

var=`node -p -e 'JSON.parse(process.argv[1]).private_key' "$value"`

dest=jsonkey.key
echo "$var" > "$dest"

openssl rsa -in jsonkey.key | openssl pkcs12 -password pass:notasecret -export -nocerts -out key.p12