函数名称:openssl_x509_checkpurpose()
函数描述:此函数用于检查给定的X.509证书是否适用于指定的目的。
适用版本:PHP 4 >= 4.0.6, PHP 5, PHP 7
语法:openssl_x509_checkpurpose(resource $x509cert, int $purpose [, array $cainfo = array() [, string $untrustedfile = NULL]]): bool
参数:
返回值:如果证书适用于指定的目的,则返回true;否则返回false。
示例:
// 创建X.509证书资源句柄
$cert = openssl_x509_read(file_get_contents('example.pem'));
// 检查证书是否适用于SSL/TLS客户端连接
$purpose = X509_PURPOSE_SSL_CLIENT;
$result = openssl_x509_checkpurpose($cert, $purpose);
if ($result) {
echo "该证书适用于SSL/TLS客户端连接";
} else {
echo "该证书不适用于SSL/TLS客户端连接";
}
// 释放证书资源句柄
openssl_x509_free($cert);
注意事项: