php / 8.1.5 / function.openssl-spki-export.html /

openssl_spki_export

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

openssl_spki_exportExports a valid PEM formatted public key signed public key and challenge

Description

openssl_spki_export(string $spki): string|false

Exports PEM formatted public key from encoded signed public key and challenge

Parameters

spki

Expects a valid signed public key and challenge

Return Values

Returns the associated PEM formatted public key or false on failure.

Errors/Exceptions

Emits an E_WARNING level error if an invalid argument is passed via the spki parameter.

Examples

Example #1 openssl_spki_export() example

Extracts the associated PEM formatted public key or NULL on failure.

<?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;
}
?>

Example #2 openssl_spki_export() example from <keygen>

Extracts the associated PEM formatted public key issued from the <keygen> element

<?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">

See Also

© 1997–2021 The PHP Documentation Group
Licensed under the Creative Commons Attribution License v3.0 or later.
https://www.php.net/manual/en/function.openssl-spki-export.php