Skip to content

Instantly share code, notes, and snippets.

@jamsesso
Last active December 21, 2015 18:18
Show Gist options
  • Save jamsesso/519e43102f30334ff1d7 to your computer and use it in GitHub Desktop.
Save jamsesso/519e43102f30334ff1d7 to your computer and use it in GitHub Desktop.
authenticate_message(message) {
secret_key = get_secret_key(message.public_key)
my_signature = sprintf("payload=%s&public_key=%s&timestamp=%s&type=%s",
url_encode(message.payload),
url_encode(message.public_key),
url_encode(message.timestamp),
url_encode(message.type))
return hmac_sha256(my_signature, secret_key) == message.signature
}
on_message_received(message) {
if(authenticate_message(message)) {
Do something sensative, like saving the data.
}
else {
The message has an invalid signature! Throw it away.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment