Skip to content

Instantly share code, notes, and snippets.

@SP3269
Created May 3, 2019 23:19
Show Gist options
  • Save SP3269/a766709e7aeadc92a953dd253bb53b6a to your computer and use it in GitHub Desktop.
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)
#! /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
@jgassie
Copy link

jgassie commented Aug 9, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment