Last active
August 9, 2019 11:07
-
-
Save horttanainen/a3600740f78e6ae0dd43b8cc65ae171a to your computer and use it in GitHub Desktop.
Certificate to PEM
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/env bash | |
JS=' | |
function certToPEM(cert) { | |
if (cert.indexOf("BEGIN CERTIFICATE") === -1 && cert.indexOf("END CERTIFICATE") === -1) { | |
return `-----BEGIN CERTIFICATE-----\n${cert.match(/.{1,64}/g).join("\n")}\n-----END CERTIFICATE-----\n`; | |
} else { | |
return cert; | |
} | |
} | |
process.stdin.resume(); | |
process.stdin.setEncoding("utf8"); | |
var cert = ""; | |
process.stdin.on("data", function(buf) { | |
cert += buf; | |
}); | |
process.stdin.on("end", function() { | |
console.log(certToPEM(cert)); | |
}); | |
' | |
node -e "$JS" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment