PHP openssl_x509_parse 没有 return CSR 的数据

PHP openssl_x509_parse doesn't return data for CSR

我使用以下命令生成 CSR:

openssl req -nodes -newkey rsa:2048 -keyout mytestserver.key -out mytestserver.csr

我尝试使用以下 PHP 代码解码 mytestserver.csr

<?php

$mydata="-----BEGIN CERTIFICATE REQUEST-----
MIICyDCCAbACAQAwgYIxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJOSDEQMA4GA1UE
BxMHQ29uY29yZDESMBAGA1UEChMJTXljb21wYW55MQswCQYDVQQLEwJJVDETMBEG
A1UEAxMKbXl0ZXN0LmNvbTEeMBwGCSqGSIb3DQEJARYPdGVzdGVyQHRlc3QuY29t
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3CcljODQKIJQ9xnPFydW
E6fRphmfxtDZF46/J6jT7ctzG3Mv//8p9ene60BCDIWdWiDXvUUUc02nb/qiiaP5
lALl6XeLKOKs6ZEC/lknDfgOBSjqvLz+UzlOXjRdhBpaawaEbVw4rh6idHWIOFGT
lzuHmE8YBmJ7R+tfhmEETk5XtPRZ3RL173HH2R/f2YCh0uhMr4GqXVfHtWrkpiw7
gXjvaXFeQhslTSP7Pru8j39uYKqubwLTyJ1uoqHVVOIqmswz+WfSvn+c86VK44p0
oQQnFL1gHoUWBHSbTmU49ufOWog9oLHOo9GUnMRg9TntGL0s55rfmSTZ+qtyB8Lc
7wIDAQABoAAwDQYJKoZIhvcNAQEEBQADggEBALglJeJUBEmxTy1hE0jG4cPAaJe5
FOqaVCUDm4YeoTpLfYLgE7ZkWuqkhZdw4TR9wu4DkiYo9z94avrKzFj2Kq1JHjUX
weYAHzGxtFO2IUuz7DSGfSvfJ0mMkAH+QtaxNUV2olnrdA8T5hRzgbZT2RTCc0GV
iSyCKXj4O/yRt0lbBCdM/Lja3Yga2BrFtvcsqnaDO6kIj+x1YCpL3cpRsm+3XbvH
dE02+hB/iHC0bE4lQciPCASOiXbMWASWxofFjyRCP+Ha+np/FqoxRF6DIUu10dCS
wV2kkbQQhNsFuMzCJvYudsmG1ULUfjUTvCAgO9kdBweNg3nklzetoSWoE5k=
-----END CERTIFICATE REQUEST-----";

print ("\r\n begin");
print_r(openssl_x509_parse($mydata));

print ("\r\n end");

但它给出了一个空结果。

知道如何使用 PHP 的 OpenSSL 库来解码我生成的 RSA CSR 吗?

openssl_x509_parse() is used to "parse an X509 certificate." To parse a certificate signing request, you can use openssl_csr_get_subject() and openssl_csr_get_public_key().

要检索 public 关键详细信息,您将使用 openssl_pkey_get_details():

$keyres = openssl_csr_get_public_key($mydata);
$key = openssl_pkey_get_details($keyres);
echo "$key[bits] bit public key follows:\n$key[key]\n";