Last active
December 21, 2015 18:18
-
-
Save jamsesso/519e43102f30334ff1d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
authenticate_message(message) { | |
secret_key = get_secret_key(message.public_key) | |
my_signature = sprintf("payload=%s&public_key=%s×tamp=%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