Skip to content

Instantly share code, notes, and snippets.

@dulgeoion
Created November 26, 2019 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dulgeoion/9d1e37c45f909d5f302da5732d7961c8 to your computer and use it in GitHub Desktop.
Save dulgeoion/9d1e37c45f909d5f302da5732d7961c8 to your computer and use it in GitHub Desktop.
const crypto = require("crypto");
const sign = (data, key, method, route) => {
var md = crypto.createHash("sha1");
md.update(
JSON.stringify(data)
.concat(key.toString())
.concat(method.toString())
.concat(route.toString())
);
return md.digest("hex");
};
const verify = (data, key, method, route, hash) => {
let hashToVerify = sign(data, key, method, route);
return hashToVerify === hash;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment