Created
May 3, 2019 23:19
-
-
Save SP3269/a766709e7aeadc92a953dd253bb53b6a to your computer and use it in GitHub Desktop.
PowerShell script to convert Google Cloud Platform service account JSON credentials to PFX credentials (for using with New-Jwt from my JWT module)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/pwsh -nop | |
$j = Get-Content "./Gsuite.json" | ConvertFrom-JSON | |
$priv = $j.private_key | |
$pub = (Invoke-RestMethod $j.client_x509_cert_url).($j.private_key_id) | |
$rnd = Get-Random 1000001 | |
$priv | Out-File ".\priv$rnd.key" | |
$pub | Out-File ".\pub$rnd.cer" | |
openssl pkcs12 -export -in "pub$rnd.cer" -inkey "priv$rnd.key" -out "pfx$rnd.p12" -password pass:notasecret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the response! If I had just used PS7 it would have been fine. I had to change the encoding on both the CER and the KEY file to remove the LE BOM established from running under PS 5.1 (unlike PS 7) and just left them as UTF-8 encoding, then it processed the openssl command fine. The line feed characters were not an issue it seems. I also found that I made a p12 for the same service account years ago (of course!). Thanks again!