Skip to content

Commit

Permalink
fix(php8): Deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
craigAtCD committed Aug 11, 2021
1 parent 0620bcc commit 81a0f78
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
12 changes: 7 additions & 5 deletions src/Traits/Decrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public function parseCipherData($cipherData)

return [
'cipherText' => base64_decode($cipherParts[0]),
'version' => base64_decode($cipherParts[1]),
'iv' => base64_decode($cipherParts[2]),
'version' => base64_decode($cipherParts[1]),
'iv' => base64_decode($cipherParts[2]),
];
}

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

[
'cipherText' => $cipherText,
'version' => $version,
'iv' => $algorithmIv
'version' => $version,
'iv' => $algorithmIv
] = $this->parseCipherData($cipherData);

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

if (openssl_open($cipherText, $decryptedData, base64_decode($key), $privateKey, $algorithm, $algorithmIv)) {
openssl_free_key($privateKey);
if (\PHP_VERSION_ID < 80000) {
openssl_free_key($privateKey);
}

return $decryptedData;
}
Expand Down
16 changes: 9 additions & 7 deletions src/Traits/Encrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ protected function performEncryption($data, $version = null): array
$algorithmIv = $this->generateIV($encryptionVersion);
$algorithm = $this->versions[$encryptionVersion];

$publicKeys = collect($this->publicKey)->map(function($publicKey, $id) {
$key = openssl_pkey_get_public($publicKey);
if(!$key){
$publicKeys = collect($this->publicKey)->map(function ($publicKey, $id) {
$key = openssl_pkey_get_public($publicKey);
if (! $key) {
Log::critical('Public key id: [' . $id . '] Is invalid');
}
return $key;
}
return $key;
})->filter();

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

return [
'keys' => $mappedKeys,
'keys' => $mappedKeys,
'cipherText' => base64_encode($encryptedData)
. ':'
. base64_encode($encryptionVersion)
Expand Down

0 comments on commit 81a0f78

Please sign in to comment.