We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

HMAC SHA1 in Coldfusion?

Medium Priority
1,849 Views
Last Modified: 2013-12-20
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
Comment
Watch Question

Commented:
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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
HMAC sha1 isn't just sha1:

http://en.wikipedia.org/wiki/HMAC

Author

Commented:
Ah! it appears theres a CF_HMAC tag. Thats exactly what I was looking for.

Thanks.

Commented:
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.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.