EasyCFM.COM ColdFusion Forums / PHP to CFML / PHP function to CF

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: PHP function to CF

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

mnkyhead
12-10-2007 @ 1:49 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 4
Joined: Dec 2007

I need help converting this php function:

function php_hmacsha1($data, $key) {
$klen = strlen($key);
$blen = 64;
$ipad = str_pad("", $blen, chr(0x36));
$opad = str_pad("", $blen, chr(0x5c));

if ($klen <= $blen) {
while (strlen($key) < $blen) {
$key .= "\0";
} #zero-fill to blocksize
} else {
$key = cybs_sha1($key); #if longer, pre-hash key
}
$key = str_pad($key, strlen($ipad) + strlen($data), "\0");
return cybs_sha1(($key ^ $opad) . cybs_sha1($key ^ $ipad . $data));
}

to Coldfusion code.
the part that is throwing me are the last 2 lines, and how to convert a php bitxor to a cf bitxor.
here is what I have in cf so far, it is a little messy because I have been doing some debugging....

<cffunction name="hmacsha1" access="private" returntype="string">
<cfargument name="data" type="string" required="yes">
<cfargument name="key" type="string" required="yes">
<cfscript>
var klen = Len(key);
var blen = 64;
var ipad = str_pad("", blen, ToString(chr(54)));
var opad = str_pad("", blen, ToString(chr(92)));
var str1 = "";
var str2 = "";
var str3 = "";
var sha = "";
if (klen LTE blen) {
while (len(key) LT blen) {
key = key & "0";
}
} else {
str1 = cybs_sha1(key);
}
//str2 = str_pad(str1, len(ipad) + len(data), "0");
str3 = str1&data;

sha = cybs_sha1(str3);

</cfscript>
<cfdump var="#klen#<br>">
<cfdump var="#str1#<br>">
<cfdump var="#str2#<br>">
<cfdump var="#str3#<br>">
<cfdump var="#ipad#<br>">
<cfdump var="#opad#">
<cfreturn sha>
</cffunction>

thanks for the help.
Russ

This message was edited by mnkyhead on 12-10-07 @ 1:53 PM

CJ
12-10-2007 @ 2:08 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

does the livedocs page on bitxor help any?

http://livedocs.adobe.com/coldfusion/7/htmldocs/00000413.htm

-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com

Teachers open the door. You enter by yourself.
—Chinese Proverb

mnkyhead
12-10-2007 @ 2:41 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 4
Joined: Dec 2007

yeah I looked at that earlier, php bitxor can take either a string or an intiger, where as CF xor can only take an integer.  one of my problems is I don't know enough about bitwise operations.

This message was edited by mnkyhead on 12-10-07 @ 2:41 PM

CJ
12-10-2007 @ 3:18 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

unfortunately, neither do i Frown  

that's why i was hoping the docs might help.

hopefully somebody else smarter than us can chime in and clear things up.

-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com

Teachers open the door. You enter by yourself.
—Chinese Proverb


Website Designed and Developed by Pablo Varando.