Skip to content

Commit fd6ba26

Browse files
Encode, Decode deprecated issue
1 parent 903b722 commit fd6ba26

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/Keys.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,22 @@ public function generateScopedSearchKey(
5959
string $searchKey,
6060
array $parameters
6161
): string {
62-
$paramStr = json_encode($parameters, JSON_THROW_ON_ERROR);
63-
$digest = base64_encode(hash_hmac('sha256', utf8_encode($paramStr), utf8_encode($searchKey), true));
64-
$keyPrefix = substr($searchKey, 0, 4);
65-
$rawScopedKey = sprintf('%s%s%s', utf8_decode($digest), $keyPrefix, $paramStr);
66-
return base64_encode(utf8_encode($rawScopedKey));
62+
$paramStr = json_encode($parameters, JSON_THROW_ON_ERROR);
63+
$digest = base64_encode(
64+
hash_hmac(
65+
'sha256',
66+
mb_convert_encoding($paramStr, 'UTF-8', 'ISO-8859-1'),
67+
mb_convert_encoding($searchKey, 'UTF-8', 'ISO-8859-1'),
68+
true)
69+
);
70+
$keyPrefix = substr($searchKey, 0, 4);
71+
$rawScopedKey = sprintf(
72+
'%s%s%s',
73+
mb_convert_encoding($digest, 'ISO-8859-1', 'UTF-8'),
74+
$keyPrefix,
75+
$paramStr
76+
);
77+
return base64_encode(mb_convert_encoding($rawScopedKey, 'UTF-8', 'ISO-8859-1'));
6778
}
6879

6980
/**

0 commit comments

Comments
 (0)