openssl_csr_get_public_key

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

openssl_csr_get_public_key返回 CSR 的公钥

说明

openssl_csr_get_public_key(OpenSSLCertificateSigningRequest|string $csr, bool $short_names = true): OpenSSLAsymmetricKey|false

openssl_csr_get_public_key()csr 中提取公钥供其他功能使用。

参数

csr

See CSR parameters for a list of valid values.

short_names
警告

该参数可以省略。

返回值

成功时返回 OpenSSLAsymmetricKey,错误则返回 false

更新日志

版本 说明
8.0.0 成功时此函数现在返回 OpenSSLAsymmetricKey 实例;之前返回类型 OpenSSL keyresource
8.0.0 csr 现在接受 OpenSSLCertificateSigningRequest 实例;之前接受类型 OpenSSL X.509 CSRresource

示例

示例 #1 openssl_csr_get_public_key() 示例

<?php
$subject
= array(
"commonName" => "example.com",
);
$private_key = openssl_pkey_new(array(
"private_key_bits" => 2048,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
));
$csr = openssl_csr_new($subject, $private_key, array('digest_alg' => 'sha256') );
$public_key = openssl_csr_get_public_key($csr);
$info = openssl_pkey_get_details($public_key);
echo
$info['key'];
?>

参见

add a note add a note

User Contributed Notes 1 note

up
-2
php at siemenroorda dot nl
15 years ago
Function openssl_pkey_get_details can read this resource. Try:

<?php
  print_r
(openssl_pkey_get_details(openssl_csr_get_public_key($csr)));
?>
To Top