Skip to content

Instantly share code, notes, and snippets.

@bentonporter
Created June 7, 2012 20:51
Show Gist options
  • Save bentonporter/2891463 to your computer and use it in GitHub Desktop.
Save bentonporter/2891463 to your computer and use it in GitHub Desktop.
Ruby - HMAC-SHA256 example
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()
@activeliang
Copy link

secure_hash = OpenSSL::HMAC.hexdigest('SHA256', <key>, <data>)

thx~

@Mth0158
Copy link

Mth0158 commented Feb 1, 2022

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