Hmac-Sha1 encode for mIRC
Platform: mIRC
Published Sep 13, 2010
Updated Mar 16, 2011
I wrote this hash encryption alias because it is needed for OAuth Authentication.
Without a hmac-sha1 function, you cannot create the signatures needed to use most major api's.(ie. Facebook, Twitter, etc.)
hmac-sha1 is also used for lots of other keyed authentication.
More information on hmac-sha1 can be found here -->>
http://www.faqs.org/rfcs/rfc2104.html
For anyone who is wondering, I will begin working on updating some of my twitter scripts to OAuth/Xauth Tomorrow.
I will also be posting a Twitter Signature alias as soon as I get it written.
This isn't a lot of code, but it was an extremely taxing project.
For those posts/notices I have not responded to, I apologize.
I'll try to catch up asap.
As for a mIRC 7 version of this, I'll try to get to it in a couple of weeks.
If you need a hmac-md5 routine , just change 64 to 32 and $sha1 to $md5
**Note** The result of the hmac-sha1 is base 64 encoded as a final step to make it compatible with OAuth.
*Updated* Original snippet is here -->>
http://pastebin.com/XKrMHWf7 ;hmacsha1 by Ford_Lawnmower irc.GeekShed.net #Script-Help
;Syntax hmacsha1 key message or $hmacsha1(key,message)
alias hmacsha1 {
var %key $1, %data $2
bset -c &key 1 $regsubex(%key,/(.)/g, $asc(\1) $chr(32))
bset -c &data 1 $regsubex(%data,/(.)/g, $asc(\1) $chr(32))
if ($bvar(&key,0) > 64) bset -c &key 1 $hex2chr($sha1(&key,1))
bset -c &ipad 1 $xorall($str($+(54,$chr(32)),64),$bvar(&key,1-))
bset -c &opad 1 $xorall($str($+(92,$chr(32)),64),$bvar(&key,1-))
bcopy &ipad $calc($bvar(&ipad,0) + 1) &data 1 -1
bset -c &ipad 1 $hex2chr($sha1(&ipad,1))
bcopy &opad $calc($bvar(&opad,0) + 1) &ipad 1 -1
bset -c &return 1 $hex2chr($sha1(&opad,1))
noop $encode(&return, mb)
$iif($isid,return,$iif(#,say,echo -a)) $bvar(&return, 1-).text
}
alias -l hex2chr return $regsubex($1-,/(.{2})/g, $base(\t,16,10) $chr(32))
alias -l xorall {
var %p $1, %k $2, %end $iif($regex($1,/([\d]{1,})/g) > $regex($2,/([\d]{1,})/g),$v1,$v2)
return $regsubex($str(.,%end),/(.)/g,$+($xor($iif($gettok(%p,\n,32),$v1,0),$iif($gettok(%k,\n,32),$v1,0)),$chr(32)))
}