Skip to content

Commit

Permalink
Merge pull request #44 from typesense/deprecated-issue
Browse files Browse the repository at this point in the history
Encode, Decode deprecated issue
  • Loading branch information
arayiksmbatyan authored Aug 22, 2023
2 parents 903b722 + fd6ba26 commit 23e1789
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/Keys.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,22 @@ public function generateScopedSearchKey(
string $searchKey,
array $parameters
): string {
$paramStr = json_encode($parameters, JSON_THROW_ON_ERROR);
$digest = base64_encode(hash_hmac('sha256', utf8_encode($paramStr), utf8_encode($searchKey), true));
$keyPrefix = substr($searchKey, 0, 4);
$rawScopedKey = sprintf('%s%s%s', utf8_decode($digest), $keyPrefix, $paramStr);
return base64_encode(utf8_encode($rawScopedKey));
$paramStr = json_encode($parameters, JSON_THROW_ON_ERROR);
$digest = base64_encode(
hash_hmac(
'sha256',
mb_convert_encoding($paramStr, 'UTF-8', 'ISO-8859-1'),
mb_convert_encoding($searchKey, 'UTF-8', 'ISO-8859-1'),
true)
);
$keyPrefix = substr($searchKey, 0, 4);
$rawScopedKey = sprintf(
'%s%s%s',
mb_convert_encoding($digest, 'ISO-8859-1', 'UTF-8'),
$keyPrefix,
$paramStr
);
return base64_encode(mb_convert_encoding($rawScopedKey, 'UTF-8', 'ISO-8859-1'));
}

/**
Expand Down

0 comments on commit 23e1789

Please sign in to comment.