Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Aug 6, 2021
1 parent a504fd6 commit 827bc1d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Illuminate/Encryption/Encrypter.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public static function generateKey($cipher)
public function encrypt($value, $serialize = true)
{
$iv = random_bytes(openssl_cipher_iv_length($this->cipher));

$tag = in_array($this->cipher, ['AES-128-GCM', 'AES-256-GCM']) ? '' : null;

// First we will encrypt the value using OpenSSL. After this is encrypted we
Expand All @@ -108,7 +109,9 @@ public function encrypt($value, $serialize = true)
// Once we get the encrypted value we'll go ahead and base64_encode the input
// vector and create the MAC for the encrypted value so we can then verify
// its authenticity. Then, we'll JSON the data into the "payload" array.
$mac = $this->hash($iv = base64_encode($iv), $value, $tag = $tag ? base64_encode($tag) : '');
$mac = $this->hash(
$iv = base64_encode($iv), $value, $tag = $tag ? base64_encode($tag) : ''
);

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

Expand Down Expand Up @@ -146,6 +149,7 @@ public function decrypt($payload, $unserialize = true)
$payload = $this->getJsonPayload($payload);

$iv = base64_decode($payload['iv']);

$tag = empty($payload['tag']) ? null : base64_decode($payload['tag']);

// Here we will decrypt the value. If we are able to successfully decrypt it
Expand Down Expand Up @@ -180,6 +184,7 @@ public function decryptString($payload)
*
* @param string $iv
* @param mixed $value
* @param string $tag
* @return string
*/
protected function hash($iv, $value, $tag = '')
Expand Down

0 comments on commit 827bc1d

Please sign in to comment.