Created
December 1, 2025 17:49
-
-
Save defanator/462c8a217c2724d6fd96c55ffe2608df to your computer and use it in GitHub Desktop.
Script to convert PFX / PKCS#12 bundle to JSON
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/env bash | |
| set -euo pipefail | |
| usage() { | |
| cat <<EOF | |
| usage: $(basename "$0") bundle.p12 outfile.json | |
| EOF | |
| exit 0 | |
| } | |
| if [ $# -lt 2 ]; then | |
| usage | |
| fi | |
| p12="$1" | |
| outfile="$2" | |
| echo "Converting ${p12} to ${outfile}..." | |
| key=$(openssl pkcs12 -legacy -in "${p12}" -nocerts -nodes | base64) | |
| cert=$(openssl pkcs12 -legacy -in "${p12}" -clcerts -nokeys | base64) | |
| enddate=$(echo "${cert}" | base64 -d | openssl x509 -noout -enddate | cut -d '=' -f 2) | |
| printf '{"cert":"%s","key":"%s"}' "${cert}" "${key}" >"${outfile}" | |
| printf "JSON saved to %s, certificate expires on %s.\n" "${outfile}" "${enddate}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment