openssl_csr_new

PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8
openssl_csr_new - Generates a CSR
Manual
Code Examples

openssl_csr_new(
     array$distinguished_names,
     OpenSSLAsymmetricKeyprivate_key,
     [array|null$options = null],
     [array|null$extra_attributes = null]
): OpenSSLCertificateSigningRequest|false

openssl_csr_new generates a new CSR (Certificate Signing Request) based on the information provided by distinguished_names.

Note:

You need to have a valid openssl.cnf installed for this function to operate correctly. See the notes under the installation section for more information.

Parameters

distinguished_names

The Distinguished Name or subject fields to be used in the certificate.

private_key

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). The corresponding public portion of the key will be used to sign the CSR.

options

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 of 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.

Configuration overrides
options key type openssl.conf equivalent description
digest_alg string default_md Digest method or signature hash, usually one of openssl_get_md_methods
x509_extensions string x509_extensions Selects which extensions should be used when creating an x509 certificate
req_extensions string req_extensions Selects which extensions should be used when creating a CSR
private_key_bits int default_bits Specifies how many bits should be used to generate a private key
private_key_type int none Specifies the type of private key to create. This can be one of OPENSSL_KEYTYPE_DSA, OPENSSL_KEYTYPE_DH, OPENSSL_KEYTYPE_RSA or OPENSSL_KEYTYPE_EC. The default value is OPENSSL_KEYTYPE_RSA.
encrypt_key bool encrypt_key Should an exported key (with passphrase) be encrypted?
encrypt_key_cipher int none One of cipher constants.
curve_name string none One of openssl_get_curve_names.
config string N/A Path to your own alternative openssl.conf file.

extra_attributes

extra_attributes is used to specify additional configuration options for the CSR. Both distinguished_names and extra_attributes are associative arrays whose keys are converted to OIDs and applied to the relevant part of the request.

Return Values

Returns the CSR or false on failure.

Changelog

Version Description
8.0.0 On success, this function returns an OpenSSLCertificateSigningRequest instance now; previously, a resource of type OpenSSL X.509 CSR was returned.
8.0.0 private_key accepts an OpenSSLAsymmetricKey instance now; previously, a resource of type OpenSSL key was accepted.
7.1.0 options now also supports curve_name.

Related Functions

Example of openssl_csr_new

Show all examples for openssl_csr_new

PHP Version:


Function openssl_csr_new:

OpenSSL Functions

Most used PHP functions