Skip to content

Instantly share code, notes, and snippets.

@cobusc
Last active December 15, 2020 14:15
Show Gist options
  • Save cobusc/6881518 to your computer and use it in GitHub Desktop.
Save cobusc/6881518 to your computer and use it in GitHub Desktop.
HMAC signature calculation: command line example

Example of how to calculate an HMAC signature using command line utilities:

echo -n "/path/subscribe?account_id=my_account&club_id=club%20id&msisdn=27820000000&timestamp=2012-05-29T15%3A00%3A12Z" | openssl dgst -sha256 -hmac "secret_value" -binary | base64    
@derricksimpson
Copy link

This is very handy! I stumbled upon this, and tried it out for a use-case I was working with. I discovered that the quotes around secret_value were also getting interpreted as part of the secret value.

@cobusc
Copy link
Author

cobusc commented Dec 15, 2020

This is very handy! I stumbled upon this, and tried it out for a use-case I was working with. I discovered that the quotes around secret_value were also getting interpreted as part of the secret value.

@derricksimpson Thanks for pointing that out. I have changed the quotes to be normal ASCII double quotes, in which case it works fine:

echo -n "/path/subscribe?account_id=my_account&club_id=club%20id&msisdn=27820000000&timestamp=2012-05-29T15%3A00%3A12Z" | openssl dgst -sha256 -hmac "secret_value" -binary | base64   

PuNpNuWU4//lwwRb+Cs4T48/J0/za1V4KsbU85ScTnI=

and

echo -n "/path/subscribe?account_id=my_account&club_id=club%20id&msisdn=27820000000&timestamp=2012-05-29T15%3A00%3A12Z" | openssl dgst -sha256 -hmac secret_value -binary | base64   

PuNpNuWU4//lwwRb+Cs4T48/J0/za1V4KsbU85ScTnI=

returns the same value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment