array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.openssl-spki-export.php', 1 => 'openssl_spki_export', ), 'up' => array ( 0 => 'ref.openssl.php', 1 => 'OpenSSL 函数', ), 'prev' => array ( 0 => 'function.openssl-spki-export-challenge.php', 1 => 'openssl_spki_export_challenge', ), 'next' => array ( 0 => 'function.openssl-spki-new.php', 1 => 'openssl_spki_new', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/openssl/functions/openssl-spki-export.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5 >= 5.6.0, PHP 7, PHP 8)
openssl_spki_export — 通过签名公钥和 challenge 导出一个可用的 PEM 格式的公钥
spki
期望一个有效的签名公钥和 challenge 字符串。
返回关联的 PEM 格式的公钥,失败则返回 false
。
如果传递给 spki
参数是不可用的参数,则会抛出 E_WARNING
级别的警告。
示例 #1 openssl_spki_export() 示例
成功,返回关联的 PEM 格式的公钥,失败则返回 NULL.
<?php
$pkey = openssl_pkey_new('secret password');
$spkac = openssl_spki_new($pkey, 'challenge string');
$pubKey = openssl_spki_export(preg_replace('/SPKAC=/', '', $spkac));
if ($pubKey) {
echo $pubKey;
}
?>
示例 #2 openssl_spki_export() 来自 <keygen> 的示例
通过 <keygen> 元素导出关联的 PEM 格式的公钥:
<?php
$spkac = openssl_spki_export(preg_replace('/SPKAC=/', '', $_POST['spkac']));
if ($spkac != NULL) {
echo $spkac;
} else {
echo "Extraction of pub key failed";
}
?>
<keygen name="spkac" challenge="challenge string" keytype="RSA">