Created
June 7, 2012 20:51
-
-
Save bentonporter/2891463 to your computer and use it in GitHub Desktop.
Ruby - HMAC-SHA256 example
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
require 'openssl' | |
require 'Base64' | |
key = "secret-key" | |
data = "some data to be signed" | |
Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha256'), key, data)).strip() |
@A1iAshoor's example is what Stripe is using in its libraries. In case anyone else also writing tests for your webhooks.
If you came here (like me) looking for a quick hint on how to encode hmac sha256 for Facebook's appsecret_proof parameter, this is what you are looking for:
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), <app_secret>, <user_access_token>)
:)
Thanks, it works like a charm.
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), <app_secret>, <user_access_token>)
Thanks, it worked well here too!
secure_hash = OpenSSL::HMAC.hexdigest('SHA256', <key>, <data>)
thx~
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), <app_secret>, <user_access_token>)
Worked perfectly for Facebook API, thank you @gr8bit
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
+1 for @gr8bit suggestion