Skip to content

Commit 74f853c

Browse files
committed
Fixing openssl_encrypt
1 parent b360a56 commit 74f853c

File tree

5 files changed

+36
-31
lines changed

5 files changed

+36
-31
lines changed

generated/functionsList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,6 @@
602602
'openssl_decrypt',
603603
'openssl_dh_compute_key',
604604
'openssl_digest',
605-
'openssl_encrypt',
606605
'openssl_open',
607606
'openssl_pbkdf2',
608607
'openssl_pkcs12_export_to_file',
@@ -1074,4 +1073,5 @@
10741073
'apc_fetch',
10751074
'apcu_fetch',
10761075
'preg_replace',
1076+
'openssl_encrypt',
10771077
];

generated/openssl.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -340,35 +340,6 @@ function openssl_digest(string $data, string $method, bool $raw_output = false):
340340
}
341341

342342

343-
/**
344-
* Encrypts given data with given method and key, returns a raw
345-
* or base64 encoded string
346-
*
347-
* @param string $data The plaintext message data to be encrypted.
348-
* @param string $method The cipher method. For a list of available cipher methods, use openssl_get_cipher_methods.
349-
* @param string $key The key.
350-
* @param int $options options is a bitwise disjunction of the flags
351-
* OPENSSL_RAW_DATA and
352-
* OPENSSL_ZERO_PADDING.
353-
* @param string $iv A non-NULL Initialization Vector.
354-
* @param string $tag The authentication tag passed by reference when using AEAD cipher mode (GCM or CCM).
355-
* @param string $aad Additional authentication data.
356-
* @param int $tag_length The length of the authentication tag. Its value can be between 4 and 16 for GCM mode.
357-
* @return string Returns the encrypted string on success .
358-
* @throws OpensslException
359-
*
360-
*/
361-
function openssl_encrypt(string $data, string $method, string $key, int $options = 0, string $iv = "", string &$tag = null, string $aad = "", int $tag_length = 16): string
362-
{
363-
error_clear_last();
364-
$result = \openssl_encrypt($data, $method, $key, $options, $iv, $tag, $aad, $tag_length);
365-
if ($result === false) {
366-
throw OpensslException::createFromPhpError();
367-
}
368-
return $result;
369-
}
370-
371-
372343
/**
373344
* openssl_open opens (decrypts)
374345
* sealed_data using the private key associated with

generator/config/specialCasesFunctions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
'apc_fetch',
99
'apcu_fetch',
1010
'preg_replace',
11+
'openssl_encrypt',
1112
];

lib/special_cases.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,36 @@ function preg_replace($pattern, $replacement, $subject, int $limit = -1, int &$c
159159
}
160160
return $result;
161161
}
162+
163+
/**
164+
* Encrypts given data with given method and key, returns a raw
165+
* or base64 encoded string
166+
*
167+
* @param string $data The plaintext message data to be encrypted.
168+
* @param string $method The cipher method. For a list of available cipher methods, use openssl_get_cipher_methods.
169+
* @param string $key The key.
170+
* @param int $options options is a bitwise disjunction of the flags
171+
* OPENSSL_RAW_DATA and
172+
* OPENSSL_ZERO_PADDING.
173+
* @param string $iv A non-NULL Initialization Vector.
174+
* @param string $tag The authentication tag passed by reference when using AEAD cipher mode (GCM or CCM).
175+
* @param string $aad Additional authentication data.
176+
* @param int $tag_length The length of the authentication tag. Its value can be between 4 and 16 for GCM mode.
177+
* @return string Returns the encrypted string.
178+
* @throws OpensslException
179+
*
180+
*/
181+
function openssl_encrypt(string $data, string $method, string $key, int $options = 0, string $iv = "", string &$tag = null, string $aad = "", int $tag_length = 16): string
182+
{
183+
error_clear_last();
184+
// The $tag parameter is handled in a weird way by openssl_encrypt. It cannot be provided unless encoding is AEAD
185+
if (func_num_args() <= 5) {
186+
$result = \openssl_encrypt($data, $method, $key, $options, $iv);
187+
} else {
188+
$result = \openssl_encrypt($data, $method, $key, $options, $iv, $tag, $aad, $tag_length);
189+
}
190+
if ($result === false) {
191+
throw OpensslException::createFromPhpError();
192+
}
193+
return $result;
194+
}

rector-migrate.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,6 @@ services:
603603
openssl_decrypt: 'Safe\openssl_decrypt'
604604
openssl_dh_compute_key: 'Safe\openssl_dh_compute_key'
605605
openssl_digest: 'Safe\openssl_digest'
606-
openssl_encrypt: 'Safe\openssl_encrypt'
607606
openssl_open: 'Safe\openssl_open'
608607
openssl_pbkdf2: 'Safe\openssl_pbkdf2'
609608
openssl_pkcs12_export_to_file: 'Safe\openssl_pkcs12_export_to_file'
@@ -1075,3 +1074,4 @@ services:
10751074
apc_fetch: 'Safe\apc_fetch'
10761075
apcu_fetch: 'Safe\apcu_fetch'
10771076
preg_replace: 'Safe\preg_replace'
1077+
openssl_encrypt: 'Safe\openssl_encrypt'

0 commit comments

Comments
 (0)