openssl_pkcs7_sign

FunctionMisc changes in PHP 8.2

Sign an S/MIME message.

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

openssl_pkcs7_sign Function synopsis

openssl_pkcs7_sign(
    string $input_filename,
    string $output_filename,
    OpenSSLCertificate|string $certificate,
    $private_key,
    ?array $headers,
    int $flags = PKCS7_DETACHED,
    ?string $untrusted_certificates_filename = null
  ): bool

Parameters

$input_filename

Typestring

The input file you are intending to digitally sign.

$output_filename

Typestring

The file which the digital signature will be written to.

$certificate

TypeOpenSSLCertificate|string

The X.509 certificate used to digitally sign $input_filename. See Key/Certificate parameters for a list of valid values.

$private_key

$private_key is the private key corresponding to $certificate. See Public/Private Key parameters for a list of valid values.

$headers

Type?array

$headers is an array of headers that will be prepended to the data after it has been signed (see openssl_pkcs7_encrypt for more information about the format of this parameter).

$flags

OptionalTypeintDefault valuePKCS7_DETACHED

$flags can be used to alter the output - see PKCS7 constants.

$flags accepts one or a bitmask of the following constant values:

$untrusted_certificates_filename

OptionalType?stringDefault valuenull

$untrusted_certificates_filename specifies the name of a file containing a bunch of extra certificates to include in the signature which can for example be used to help the recipient to verify the certificate that you used.

Return value

Typebool

Returns true on success, false on failure

Changes to the openssl_pkcs7_sign Function

PHP 8.2

PHP 8.0

  • Return type added: bool
  • Parameter name of parameter #1 changed: $infile to $input_filename
  • Parameter type added for parameter #1 ($input_filename): string
  • Parameter name of parameter #2 changed: $outfile to $output_filename
  • Parameter type added for parameter #2 ($output_filename): string
  • Parameter name of parameter #3 changed: $signcert to $certificate
  • Parameter type added for parameter #3 ($certificate): OpenSSLCertificate|string
  • Parameter name of parameter #4 changed: $signkey to $private_key
  • Parameter type added for parameter #5 ($headers): ?array
  • Parameter type added for parameter #6 ($flags): int
  • Parameter default value added for position #6 ($flags): PKCS7_DETACHED
  • Parameter name of parameter #7 changed: $extracertsfilename to $untrusted_certificates_filename
  • Parameter type added for parameter #7 ($untrusted_certificates_filename): ?string
  • Parameter default value added for position #7 ($untrusted_certificates_filename): null
  openssl_pkcs7_sign(
-     $infile,
+     string $input_filename,
-     $outfile,
+     string $output_filename,
-     $signcert,
+     OpenSSLCertificate|string $certificate,
-     $signkey,
+     $private_key,
-     $headers,
+     ?array $headers,
-     $flags,
+     int $flags = PKCS7_DETACHED,
-     $extracertsfilename
+     ?string $untrusted_certificates_filename = null
-   )
+   ): bool

openssl_pkcs7_sign 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