Skip to content

Commit c878a18

Browse files
committed
Merge pull request #1962 from fpirsch/master
fix incorrect padding with multibyte strings encryption
2 parents 5d63d5a + 76db206 commit c878a18

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

laravel/crypter.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ protected static function iv_size()
116116
*/
117117
protected static function pad($value)
118118
{
119-
$pad = static::$block - (Str::length($value) % static::$block);
119+
$pad = static::$block - (strlen($value) % static::$block);
120120

121121
return $value .= str_repeat(chr($pad), $pad);
122122
}
@@ -129,14 +129,7 @@ protected static function pad($value)
129129
*/
130130
protected static function unpad($value)
131131
{
132-
if (MB_STRING)
133-
{
134-
$pad = ord(mb_substr($value, -1, 1, Config::get('application.encoding')));
135-
}
136-
else
137-
{
138-
$pad = ord(substr($value, -1));
139-
}
132+
$pad = ord(substr($value, -1));
140133

141134
if ($pad and $pad <= static::$block)
142135
{
@@ -145,12 +138,7 @@ protected static function unpad($value)
145138
// as the padding appears to have been changed.
146139
if (preg_match('/'.chr($pad).'{'.$pad.'}$/', $value))
147140
{
148-
if (MB_STRING)
149-
{
150-
return mb_substr($value, 0, Str::length($value) - $pad, Config::get('application.encoding'));
151-
}
152-
153-
return substr($value, 0, Str::length($value) - $pad);
141+
return substr($value, 0, strlen($value) - $pad);
154142
}
155143

156144
// If the padding characters do not match the expected padding

0 commit comments

Comments
 (0)