Skip to content

Commit b30d019

Browse files
committed
Add overloaded Encryption::substr()
1 parent 9441ded commit b30d019

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

system/Encryption/Encryption.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public function hkdf($key, $digest = 'sha512', $salt = null, $length = null, $in
305305

306306
$prk = hash_hmac($digest, $key, $salt, true);
307307
$key = '';
308-
for ($key_block = '', $block_index = 1; self::strlen($key) < $length; $block_index ++ )
308+
for ($key_block = '', $block_index = 1; self::strlen($key) < $length; $block_index ++)
309309
{
310310
$key_block = hash_hmac($digest, $key_block . $info . chr($block_index), $prk, true);
311311
$key .= $key_block;
@@ -314,4 +314,19 @@ public function hkdf($key, $digest = 'sha512', $salt = null, $length = null, $in
314314
return self::substr($key, 0, $length);
315315
}
316316

317+
// --------------------------------------------------------------------
318+
319+
/**
320+
* Byte-safe substr()
321+
*
322+
* @param string $str
323+
* @param int $start
324+
* @param int $length
325+
* @return string
326+
*/
327+
protected static function substr($str, $start, $length = null)
328+
{
329+
return mb_substr($str, $start, $length, '8bit');
330+
}
331+
317332
}

0 commit comments

Comments
 (0)