HMAC SHA1 in Coldfusion?

Hello there,

I'm wondering if there is a simple way to implement HMAC SHA1 in coldfusion.

The PHP version looks like this:

//Calculate HMAC-SHA1 according to RFC2104
// http://www.ietf.org/rfc/rfc2104.txt
function hmacsha1($key,$data) {
   $blocksize=64;
   $hashfunc='sha1';
   if (strlen($key)>$blocksize)
       $key=pack('H*', $hashfunc($key));
   $key=str_pad($key,$blocksize,chr(0x00));
   $ipad=str_repeat(chr(0x36),$blocksize);
   $opad=str_repeat(chr(0x5c),$blocksize);
   $hmac = pack(
               'H*',$hashfunc(
                   ($key^$opad).pack(
                       'H*',$hashfunc(
                           ($key^$ipad).$data
                       )
                   )
               )
           );
   return bin2hex($hmac);
}

I think most of it is fairly straightforward, however I don't know if there is a good way to work with hex data in coldfusion. Any help would be appreciated.

-Umbrae
LVL 5
umbraeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RCorfmanCommented:
Depends on the CF Version, In version 7, the HASH Function supports SHA1.  There is also a custom tag for prior version. I'll look it up and get back in a minute.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
umbraeAuthor Commented:
HMAC sha1 isn't just sha1:

http://en.wikipedia.org/wiki/HMAC
umbraeAuthor Commented:
Ah! it appears theres a CF_HMAC tag. Thats exactly what I was looking for.

Thanks.
RCorfmanCommented:
I understand now. The SHA-1 part is only a piece. The EE link that I showed though was trying to do the HMAC SHA-1 though I believe.
I think this link is the macromedia custom tag to do the HMAC.
http://www.macromedia.com/cfusion/exchange/index.cfm?view=sn131&extID=1003921

The EE link showed how to implement it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.