Thursday, October 9, 2025
HomeLanguagesPHP openssl_spki_export_challenge() Function

PHP openssl_spki_export_challenge() Function

The openssl_spki_export_challenge() function is an inbuilt function in PHP and is used to export the signed public key and the challenge associated with it. It verifies a signed public key and challenge.

Syntax:

string openssl_spki_export_challenge( string &$spkac )

Parameters: This function accepts single parameter as mentioned above and described below:

  • $spkac: This parameter is a format for sending a Certification Signing Request which encodes a public key that can be manipulated using openssl.

Return Values: This function returns the associated challenge string or NULL on failure.

Errors/Exceptions: If an invalid argument is passed using the “spkac” parameter, the E_WARNING level emits an error.

Below program illustrate the openssl_spki_export_challenge() function in PHP:

Program:

PHP




<?php
  
$pkey   = openssl_pkey_new(array("spki"));
$inputChallengeString = "neveropen";
  
// Generate a new key pair using 
// "neveropen" as challenge string
$spkac = openssl_spki_new(
        $pkey, $inputChallengeString);
   
// Extract challenge key from key
$extractedChallengeString
    openssl_spki_export_challenge(
    preg_replace('/SPKAC=/', '', $spkac));
   
//if challenge string is not null
if (! is_null($extractedChallengeString)) {
    echo "Used challenge string is:" 
        . $inputChallengeString."\n";
          
    // print challenge key
    echo "Extracted challenge string is:"
        . $extractedChallengeString . "\n";
}
  
?>


Output:

Used challenge string is:neveropen
Extracted challenge string is:neveropen

Reference: https://www.php.net/manual/en/function.openssl-spki-export-challenge.php

RELATED ARTICLES

Most Popular

Dominic
32345 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6714 POSTS0 COMMENTS
Nicole Veronica
11877 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11940 POSTS0 COMMENTS
Shaida Kate Naidoo
6834 POSTS0 COMMENTS
Ted Musemwa
7094 POSTS0 COMMENTS
Thapelo Manthata
6789 POSTS0 COMMENTS
Umr Jansen
6791 POSTS0 COMMENTS