Skip to content

Commit

Permalink
Update the encrypt algorithm to not escape slashes in json to provide…
Browse files Browse the repository at this point in the history
… deterministic encryption sizes. (#31721)
  • Loading branch information
patrickcarlohickman authored Mar 8, 2020
1 parent 6495758 commit 19c9830
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Encryption/Encrypter.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function encrypt($value, $serialize = true)
// its authenticity. Then, we'll JSON the data into the "payload" array.
$mac = $this->hash($iv = base64_encode($iv), $value);

$json = json_encode(compact('iv', 'value', 'mac'));
$json = json_encode(compact('iv', 'value', 'mac'), JSON_UNESCAPED_SLASHES);

if (json_last_error() !== JSON_ERROR_NONE) {
throw new EncryptException('Could not encrypt the data.');
Expand Down
10 changes: 10 additions & 0 deletions tests/Encryption/EncrypterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ public function testEncryptionUsingBase64EncodedKey()
$this->assertSame('foo', $e->decrypt($encrypted));
}

public function testEncryptedLengthIsFixed()
{
$e = new Encrypter(str_repeat('a', 16));
$lengths = [];
for ($i = 0; $i < 100; $i++) {
$lengths[] = strlen($e->encrypt('foo'));
}
$this->assertSame(min($lengths), max($lengths));
}

public function testWithCustomCipher()
{
$e = new Encrypter(str_repeat('b', 32), 'AES-256-CBC');
Expand Down

0 comments on commit 19c9830

Please sign in to comment.