Redo: Making HMAC Hashes in Ruby

This is a post from May 5th, 2007 that was one my old blog. I let it go a while back and have now started blogging again. I’m posting this article again because it may still be useful for some people. It’s actually still generating traffic to my domain!

I was trying to make a quick little Ruby script for Authorize.net SIM for one of my clients and became really annoyed trying to find a flipping document, tutorial or README on HMAC for Ruby. I eventually found something rather unrelated to what I am doing but had the little piece of code that saved my life that day.

OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('md5'), key, data)

How handy, HMAC lives right inside Ruby’s OpenSSL libraries—just fill in the key and data variables. Before I found this I tried installing HMAC Libraries directly but with no luck obviously. It still amazes me how little documentation is out there for HMAC with Ruby.