Last active
August 13, 2024 20:41
-
-
Save jinnko/d6867ce326e8b6e88975 to your computer and use it in GitHub Desktop.
Take a PEM format file as input and split out certs and keys into separate files.
This file contains 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/awk -f | |
# | |
# Take a PEM format file as input and split out certs and keys into separate files | |
# | |
BEGIN { n=0; cert=0; key=0; if ( ARGC < 2 ) { print "Usage: pem-split FILENAME"; exit 1 } } | |
/-----BEGIN PRIVATE KEY-----/ { key=1; cert=0 } | |
/-----BEGIN CERTIFICATE-----/ { cert=1; key=0 } | |
split_after == 1 { n++; split_after=0 } | |
/-----END CERTIFICATE-----/ { split_after=1 } | |
/-----END PRIVATE KEY-----/ { split_after=1 } | |
key == 1 { print > FILENAME "-" n ".key" } | |
cert == 1 { print > FILENAME "-" n ".crt" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment