首页 > 解决方案 > php从csr获取subjectAltName

问题描述

晚上好,我的朋友,我使用 php 通过 openssl 函数生成了 san csr。但我无法获得 subjectAltName。请问如何从csr中提取subjetAltName?

shell_exec('openssl req -noout -text -in'. $csr)

标签: php-opensslsubject-alternative-name

解决方案


我希望这有帮助:

$r = shell_exec('openssl req -noout -text -in '. $csr)
                                             ^- a space here!

但是对于我的测试,openssl 没有打印主题替代名称,所以我将展示如何获取主题:

preg_match('/Subject:\s*(.*)\n/', $r, $matches);
$subject = $matches[1];

推荐阅读