Skip to content

Commit 81a0f78

Browse files
committed
fix(php8): Deprecated functions
1 parent 0620bcc commit 81a0f78

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/Traits/Decrypt.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public function parseCipherData($cipherData)
1212

1313
return [
1414
'cipherText' => base64_decode($cipherParts[0]),
15-
'version' => base64_decode($cipherParts[1]),
16-
'iv' => base64_decode($cipherParts[2]),
15+
'version' => base64_decode($cipherParts[1]),
16+
'iv' => base64_decode($cipherParts[2]),
1717
];
1818
}
1919

@@ -41,15 +41,17 @@ protected function performDecryption($cipherData, $key): string
4141

4242
[
4343
'cipherText' => $cipherText,
44-
'version' => $version,
45-
'iv' => $algorithmIv
44+
'version' => $version,
45+
'iv' => $algorithmIv
4646
] = $this->parseCipherData($cipherData);
4747

4848
$encryptionVersion = $this->getVersion($version);
4949
$algorithm = $this->versions[$encryptionVersion];
5050

5151
if (openssl_open($cipherText, $decryptedData, base64_decode($key), $privateKey, $algorithm, $algorithmIv)) {
52-
openssl_free_key($privateKey);
52+
if (\PHP_VERSION_ID < 80000) {
53+
openssl_free_key($privateKey);
54+
}
5355

5456
return $decryptedData;
5557
}

src/Traits/Encrypt.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ protected function performEncryption($data, $version = null): array
2424
$algorithmIv = $this->generateIV($encryptionVersion);
2525
$algorithm = $this->versions[$encryptionVersion];
2626

27-
$publicKeys = collect($this->publicKey)->map(function($publicKey, $id) {
28-
$key = openssl_pkey_get_public($publicKey);
29-
if(!$key){
27+
$publicKeys = collect($this->publicKey)->map(function ($publicKey, $id) {
28+
$key = openssl_pkey_get_public($publicKey);
29+
if (! $key) {
3030
Log::critical('Public key id: [' . $id . '] Is invalid');
31-
}
32-
return $key;
31+
}
32+
return $key;
3333
})->filter();
3434

3535
$encryptedData = null;
@@ -41,12 +41,14 @@ protected function performEncryption($data, $version = null): array
4141
// Ensure each shareKey is labelled with its corresponding key id
4242
foreach ($publicKeys as $keyId => $publicKey) {
4343
$mappedKeys[$keyId] = base64_encode($envelopeKeys[$i]);
44-
openssl_free_key($publicKey);
44+
if (\PHP_VERSION_ID < 80000) {
45+
openssl_free_key($publicKey);
46+
}
4547
$i++;
4648
}
4749

4850
return [
49-
'keys' => $mappedKeys,
51+
'keys' => $mappedKeys,
5052
'cipherText' => base64_encode($encryptedData)
5153
. ':'
5254
. base64_encode($encryptionVersion)

0 commit comments

Comments
 (0)