openssl_decrypt

FunctionParams changed in PHP 8.6

Decrypts data.

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

openssl_decrypt Function synopsis

openssl_decrypt(
    string $data,
    string $cipher_algo,
    string $passphrase,
    int $options = 0,
    string $iv = "",
    ?string $tag = null,
    ?string $aad = ""
  ): string|false

Parameters

$data

Typestring

The encrypted message to be decrypted.

$cipher_algo

Typestring

The cipher method. For a list of available cipher methods, use openssl_get_cipher_methods.

$passphrase

Typestring

The passphrase. If the passphrase is shorter than expected, it is silently padded with NUL characters; if the passphrase is longer than expected, it is silently truncated.

$options

OptionalTypeintDefault value0

$options can be one of OPENSSL_RAW_DATA, OPENSSL_ZERO_PADDING or OPENSSL_DONT_ZERO_PAD_KEY.

$iv

OptionalTypestringDefault value""

A non-null Initialization Vector. If the IV is shorter than expected, it is padded with NUL characters and warning is emitted; if the passphrase is longer than expected, it is truncated and warning is emitted.

$tag

OptionalType?stringDefault valuenull

The authentication tag in AEAD cipher mode. If it is incorrect, the authentication fails and the function returns false.

$aad

OptionalType?stringDefault value""

Additional authenticated data.

Return value

Typestring|false

The decrypted string on success or false on failure.

Changes to the openssl_decrypt Function

PHP 8.6

  • Parameter type changed for parameter #7 ($aad): string to ?string
  openssl_decrypt(
      string $data,
      string $cipher_algo,
      string $passphrase,
      int $options = 0,
      string $iv = "",
      ?string $tag = null,
-     string $aad = ""
+     ?string $aad = ""
    ): string|false

PHP 8.2

PHP 8.1

  • Parameter type changed for parameter #6 ($tag): string to ?string
  • Parameter default value changed for position #6 ($tag): "" to null
  openssl_decrypt(
      string $data,
      string $cipher_algo,
      string $passphrase,
      int $options = 0,
      string $iv = "",
-     string $tag = "",
+     ?string $tag = null,
      string $aad = ""
    ): string|false

PHP 8.0

  • Return type added: string|false
  • Parameter type added for parameter #1 ($data): string
  • Parameter name of parameter #2 changed: $method to $cipher_algo
  • Parameter type added for parameter #2 ($cipher_algo): string
  • Parameter name of parameter #3 changed: $password to $passphrase
  • Parameter type added for parameter #3 ($passphrase): string
  • Parameter type added for parameter #4 ($options): int
  • Parameter default value added for position #4 ($options): 0
  • Parameter type added for parameter #5 ($iv): string
  • Parameter default value added for position #5 ($iv): ""
  • Parameter type added for parameter #6 ($tag): string
  • Parameter default value added for position #6 ($tag): ""
  • Parameter type added for parameter #7 ($aad): string
  • Parameter default value added for position #7 ($aad): ""
  openssl_decrypt(
-     $data,
+     string $data,
-     $method,
+     string $cipher_algo,
-     $password,
+     string $passphrase,
-     $options,
+     int $options = 0,
-     $iv,
+     string $iv = "",
-     $tag,
+     string $tag = "",
-     $aad
+     string $aad = ""
-   )
+   ): string|false

PHP 7.1

  • Optional parameter added - #6: $tag
  • Optional parameter added - #7: $aad
 openssl_decrypt(
     $data,
     $method,
     $password,
     $options,
-    $iv
+    $iv,
+    $tag,
+    $aad
   )

PHP 5.4

  • Parameter name of parameter #4 changed: $raw_input to $options
  openssl_decrypt(
      $data,
      $method,
      $password,
-     $raw_input,
+     $options,
      $iv
    )

openssl_decrypt 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