Created
February 12, 2016 15:24
-
-
Save snoj/d01f4a225f2a28caa15b to your computer and use it in GitHub Desktop.
Extract certificates and key from PFX.
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
<?php | |
//Requires php with the openssl module. | |
//This is useful for instances where installing openssl isn't an option | |
// but PHP is available, like on Windows servers using WAMP. | |
//use php extractpfx.php /path/tocert.pfx "pass phrase" | |
//http://php.net/manual/en/function.openssl-pkcs12-read.php | |
if(file_exists($argv[1])) { | |
$rawpfx = file_get_contents($argv[1]); | |
$crts = array(); | |
$parsed = openssl_pkcs12_read($rawpfx, $crts, (isset($argv[2])) ? $argv[2] : ""); | |
echo $crts["cert"]; | |
if(isset($crts["pkey"])) | |
echo $crts["pkey"]; | |
if(isset($crts["extracerts"])) { | |
foreach($crts["extracerts"] as $c) { | |
echo $c; | |
} | |
} | |
} else { | |
error_log("File doesn't exist"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment