Skip to content

Instantly share code, notes, and snippets.

@FlyInk13
Last active July 11, 2019 09:51
Show Gist options
  • Save FlyInk13/aa4768136779151328194d8c1da19200 to your computer and use it in GitHub Desktop.
Save FlyInk13/aa4768136779151328194d8c1da19200 to your computer and use it in GitHub Desktop.
Документация: https://vk.cc/9AjsnM
const {createHmac} = require('crypto');
const querystring = require('querystring');
const sha256 = (string, pwd) => createHmac('sha256', pwd).update(string).digest('base64');
function checkSign(url, clientSecret) {
const parsedSearch = querystring.parse(url);
const checkSumRaw = Object
.keys(parsedSearch)
.filter((key) => /^vk_/.test(key))
.sort()
.map((key) => {
const val = parsedSearch[key];
return key + '=' + val;
})
.join('&');
const checkSum = sha256(checkSumRaw, clientSecret)
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=/g, '');
return checkSum == parsedSearch['sign'];
}
module.exports = checkSign;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment