Skip to content

Commit c87be97

Browse files
committed
test
1 parent 0fc3364 commit c87be97

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/WebPush.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Mdanter\Ecc\Crypto\Key\PublicKey;
2020
use Mdanter\Ecc\EccFactory;
2121
use Mdanter\Ecc\Serializer\Point\UncompressedPointSerializer;
22+
use Jose\Util\GCM;
2223

2324
class WebPush
2425
{
@@ -189,7 +190,12 @@ private function encrypt($userPublicKey, $payload)
189190

190191
// encrypt
191192
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-128-gcm'));
192-
$cipherText = openssl_encrypt($payload, 'aes-128-gcm', $encryptionKey, false, $iv); // base 64 encoded
193+
if (phpversion() < 7.1) {
194+
list($encryptedText, $tag) = GCM::encrypt($encryptionKey, $iv, $payload, "");
195+
$cipherText = $encryptedText.$tag;
196+
} else {
197+
$cipherText = openssl_encrypt($payload, 'aes-128-gcm', $encryptionKey, false, $iv); // base 64 encoded
198+
}
193199

194200
return array(
195201
'localPublicKey' => $localPublicKey,

0 commit comments

Comments
 (0)