[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

HMAC SHA1 in Coldfusion?

Posted on 2006-03-22
5
Medium Priority
?
1,736 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
0
Comment
Question by:umbrae
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:RCorfman
ID: 16258984
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.
0
 
LVL 16

Accepted Solution

by:
RCorfman earned 2000 total points
ID: 16259063
0
 
LVL 5

Author Comment

by:umbrae
ID: 16259152
HMAC sha1 isn't just sha1:

http://en.wikipedia.org/wiki/HMAC
0
 
LVL 5

Author Comment

by:umbrae
ID: 16259212
Ah! it appears theres a CF_HMAC tag. Thats exactly what I was looking for.

Thanks.
0
 
LVL 16

Expert Comment

by:RCorfman
ID: 16259328
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.
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…
Suggested Courses

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question