Answer the question
In order to leave comments, you need to log in
How to verify the digital signature of the VKontakte application?
Please help to solve the problem, I know that there are already such topics, but I did not find the answer to my question in them.
I need to generate a digital signature, and VK gives an example of a code that does not work Example
$sign = "";
foreach ($request->getParams() as $key => $param) {
if ($key == 'hash' || $key == 'sign') continue;
$sign .=$param;
}
$secret = 'SECRET_KEY';
$sig = $secret ? hash_hmac('sha256', $sign, $secret) : "";
$url = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$parsed_url = parse_url($url, PHP_URL_QUERY);
parse_str($parsed_url,$request);
$sign = "";
foreach ($request as $key => $param) {
if ($key == 'hash' || $key == 'sign') continue;
$sign .=$param;
}
$secret = 'Защищенный_Ключ';
$sig = $secret ? hash_hmac('sha256', $sign, $secret) : "";
$result = ($sig === $_GET['sign']) ? "Сходятся" : "Не сходятся";
Answer the question
In order to leave comments, you need to log in
replace
foreach ($request->getParams() as $key => $param) {
$sign = "";
foreach($_REQUEST AS $key => $param) {
if ($key == 'hash' || $key == 'sign') continue;
$sign .=$param;
}
$secret = '3iiyZNDFaXgR6yZMxK'; // Настройки приложения – Защищённый ключ
$sig = $secret ? hash_hmac('sha256', $sign, $secret) : "";
if( $sig === $_REQUEST['sign']) {
echo "Подписи совпали.";
} else {
echo "Разные подписи, не хорошо.";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question