File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed
src/Illuminate/Encryption Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -159,11 +159,9 @@ public function decrypt($payload, $unserialize = true)
159
159
160
160
$ iv = base64_decode ($ payload ['iv ' ]);
161
161
162
- $ tag = empty ($ payload ['tag ' ]) ? null : base64_decode ($ payload ['tag ' ]);
163
-
164
- if (self ::$ supportedCiphers [strtolower ($ this ->cipher )]['aead ' ] && strlen ($ tag ) !== 16 ) {
165
- throw new DecryptException ('Could not decrypt the data. ' );
166
- }
162
+ $ this ->ensureTagIsValid (
163
+ $ tag = empty ($ payload ['tag ' ]) ? null : base64_decode ($ payload ['tag ' ])
164
+ );
167
165
168
166
// Here we will decrypt the value. If we are able to successfully decrypt it
169
167
// we will then unserialize it and return it out to the caller. If we are
@@ -255,6 +253,23 @@ protected function validMac(array $payload)
255
253
);
256
254
}
257
255
256
+ /**
257
+ * Ensure the given tag is a valid tag given the selected cipher.
258
+ *
259
+ * @param string $tag
260
+ * @return void
261
+ */
262
+ protected function ensureTagIsValid ($ tag )
263
+ {
264
+ if (self ::$ supportedCiphers [strtolower ($ this ->cipher )]['aead ' ] && strlen ($ tag ) !== 16 ) {
265
+ throw new DecryptException ('Could not decrypt the data. ' );
266
+ }
267
+
268
+ if (! self ::$ supportedCiphers [strtolower ($ this ->cipher )]['aead ' ] && is_string ($ tag )) {
269
+ throw new DecryptException ('Unable to use tag because the cipher algorithm does not support AEAD. ' );
270
+ }
271
+ }
272
+
258
273
/**
259
274
* Get the encryption key.
260
275
*
You can’t perform that action at this time.
0 commit comments