openssl_csr_new

FunctionReturn type changed in PHP 8.2

Generates a CSR.

PHP 5
PHP 7
PHP 8.0
Improved
PHP 8.1
PHP 8.2
Improved
PHP 8.3
PHP 8.4
PHP 8.5
PHP 8.6

openssl_csr_new Function synopsis

openssl_csr_new(
    array $distinguished_names,
    &$private_key,
    ?array $options = null,
    ?array $extra_attributes = null
  ): OpenSSLCertificateSigningRequest|bool

Parameters

$distinguished_names

Typearray

The Distinguished Name or subject fields to be included in the certificate. The $distinguished_names is an associative array where the keys represent the attribute names of Distinguished Names and the values can either be strings (for single value) or arrays (if multiple values need to be set).

$private_key

Passed by reference

$private_key should be set to a private key that was previously generated by openssl_pkey_new (or otherwise obtained from the other openssl_pkey family of functions), or null variable. If its value is null variable, a new private key is generated based on the supplied $options and assigned to supplied variable. The corresponding public portion of the key will be used to sign the CSR.

$options

OptionalType?arrayDefault valuenull

By default, the information in your system openssl.conf is used to initialize the request; you can specify a configuration file section by setting the config_section_section key in $options. You can also specify an alternative OpenSSL configuration file by setting the value of the config key to the path of the file you want to use. The following keys, if present in $options behave as their equivalents in the openssl.conf, as listed in the table below.

$extra_attributes

OptionalType?arrayDefault valuenull

$extra_attributes is used to specify additional attributes for the CSR. It is an associative arrays where the keys are converted to OIDs and applied as CSR attributes.

Note that the parameter $private_key is passed by reference, and contains additional/updated context data that may be useful.

Return value

TypeOpenSSLCertificateSigningRequest|bool

Returns the CSR on success, true if CSR creation is successful but signing fails or false on failure.

Changes to the openssl_csr_new Function

PHP 8.2

  • Return type changed: OpenSSLCertificateSigningRequest|false to OpenSSLCertificateSigningRequest|bool
  • Attribute added for parameter $private_key: #[SensitiveParameter]
  openssl_csr_new(
      array $distinguished_names,
      &$private_key,
      ?array $options = null,
      ?array $extra_attributes = null
-   ): OpenSSLCertificateSigningRequest|false
+   ): OpenSSLCertificateSigningRequest|bool

PHP 8.0

  • Return type added: OpenSSLCertificateSigningRequest|false
  • Parameter name of parameter #1 changed: $dn to $distinguished_names
  • Parameter type added for parameter #1 ($distinguished_names): array
  • Parameter name of parameter #2 changed: $privkey to $private_key
  • Parameter name of parameter #3 changed: $configargs to $options
  • Parameter type added for parameter #3 ($options): ?array
  • Parameter default value added for position #3 ($options): null
  • Parameter name of parameter #4 changed: $extraattribs to $extra_attributes
  • Parameter type added for parameter #4 ($extra_attributes): ?array
  • Parameter default value added for position #4 ($extra_attributes): null
  openssl_csr_new(
-     $dn,
+     array $distinguished_names,
-     &$privkey,
+     &$private_key,
-     $configargs,
+     ?array $options = null,
-     $extraattribs
+     ?array $extra_attributes = null
-   )
+   ): OpenSSLCertificateSigningRequest|false

openssl_csr_new Function Availability

PHP VersionAvailability
PHP 8.6Upcoming Release Yes
PHP 8.5Supported (Latest) Yes
PHP 8.4Supported Yes
PHP 8.3Security-Fixes Only Yes
PHP 8.2Security-Fixes Only Yes
PHP 8.1Unsupported Yes
PHP 8.0Unsupported Yes
PHP 7.4Unsupported Yes
PHP 7.3Unsupported Yes
PHP 7.2Unsupported Yes
PHP 7.1Unsupported Yes
PHP 7.0Unsupported Yes
PHP 5.6Unsupported Yes
PHP 5.5Unsupported Yes
PHP 5.4Unsupported Yes
PHP 5.3Unsupported Yes