PHP Parse CSR



<?php
$csr='-----BEGIN CERTIFICATE REQUEST-----
MIICfTCCAWUCAQAwODELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWEx
FDASBgNVBAMMC2V4YW1wbGUuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
CgKCAQEAtR6F1AKM3sUoP/q1VK2TrV8LY/r/YnxR2/WGbuSCeSfTHz+ZNUIxHgIX
TroYQFAU55ZC4nPTxr6sBtHD2Ywp4dL7T84IWE4tFHsV30A6fhzMaGPtOpftqS1O
ETbzNJHyyYa+rkSItuoUvw/flpSNCnaAsOJg51Miw+F2Hrm97IJvNewqLgOI9jXM
CM/LYe6crc9mxtIz8raAb7RUX/qDMjS/on4rrShVUBy5rVsD+NOiYHTht+d4WoZ1
NI0irTlCjGPqHrHFDbKYkP6YW1AJQGnr10iwlTsmRG0JNmaJJGOSd1S/7HDIknvG
o93XJE5XELGYoq22HVJK9ijh2oR4MwIDAQABoAAwDQYJKoZIhvcNAQEFBQADggEB
ACiNf3UO0xdIkOb5qNpjfTm5KUWfB8jwDTbpFcH2NZnTy2vqBXFQlJzQn0XGZQ5Z
s6tOPJkNPpbbOI58j6hoTzOwfcdOtoR6AUgAFqR/VHzpqbFRvuemNUrqYz0m+kh3
2inWpu56X+I5wjmjM2e5QuUWSx3oP5fZabT60D7RjZdaNXuhw8bMqK/gSLlRNNKI
u4NNh4VlRyIS51mB6B+TMA7GQUymTeXGC1dh5f8gZRTSmaWuj7TxiSIyeNUoklq1
Nq5m1o+taITi5xvptKc8Pb37vd5R2XPUXz+iUpj7uJkNJUsPPoQaVvu+ipb4Z8G2
JKQdUMiTJ2opzTLibFdN494=
-----END CERTIFICATE REQUEST-----';
$r = openssl_csr_get_subject($csr);
print_r($r);
 
$key_resource = openssl_csr_get_public_key($csr);
$details = openssl_pkey_get_details($key_resource);
$keysize = isset($details['bits'])? $details['bits'] : 0;
 
echo "Keysize: ".$keysize."\n";?>

output:
Array
(
    [C] => US
    [ST] => California
    [CN] => example.com
)
Keysize: 2048
code snippets are licensed under Creative Commons CC-By-SA 3.0 (unless otherwise specified)