Jump to content
cezarlacatus

Autoit Hash-based message authentication code request

Recommended Posts

cezarlacatus

Hello, 

Firstly thank you that you are whatching this post....I am in a big trouble....i am trying to acces my ballance for crytopia acount using their api but i dont understend their encrypting procedures.They have published a small script written in 7 languages that can read the ballance...i just dont know how to convert it to autoit

Here are the scripts link

https://www.cryptopia.co.nz/Forum/Thread/262

 

And here is the documentation of what must include the post request

https://www.cryptopia.co.nz/Forum/Thread/256

Pleasee if someone could re-write that script for me because i just cant figure out how to do it..... I want to get my balance only and i really need your help...

Edited by JLogan3o13

Share this post


Link to post
Share on other sites
cezarlacatus

Ok i figured out...i dont need the whole script....i just need to calculate a hmac key,,,,

What is in autoit the equivalent of $hmacsignature =hash_hmac("sha256", $signature, base64_decode( $API_SECRET )); (PHP)

Share this post


Link to post
Share on other sites
cezarlacatus

Hello guys ....i need to convert this line of PHP into autoit...i need a function to calculate Hash-based message authentication code ...basically i need this line of code to work on autoit (Is a php code)

$hmacsignature =hash_hmac("sha256", $signature, $key);

Thank you verry much....i really need it ...

Share this post


Link to post
Share on other sites
Earthshine

have you checked the help file? is this link of any use?

 

Edited by Earthshine
  • Like 1

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
cezarlacatus
On 02.11.2012 at 11:02 PM, jchd said:

Some poin

On 03.11.2012 at 6:01 PM, DeltaRocked said:

Hi SkinnyWhiteGuy,

 

thanks. even I am through with the implementation. as I am at home , will be updating the code on Monday.

 

Rgds

 

On 03.11.2012 at 2:10 PM, SkinnyWhiteGuy said:

I was digging around some of my old code, and found this. Cleaned it up a little, and ensured it worked again.

 

I used Call on these, so with one HMAC function, you could use different hashing algorithms. Course, you'll have to modify the BlockSize for some hashing functions, but that's easily made an optional parameter and passed in for the larger block sizes of some hashing functions. It's also just as easy to remove the calls for the actual hash functions, if that's what you want.

 

 

#include <Crypt.au3>

Func sha1($message)
    Return _Crypt_HashData($message, $CALG_SHA1)
EndFunc

Func md5($message)
    Return _Crypt_HashData($message, $CALG_MD5)
EndFunc

Func hmac($key, $message, $hash="md5")
    Local $blocksize = 64
    Local $a_opad[$blocksize], $a_ipad[$blocksize]
    Local Const $oconst = 0x5C, $iconst = 0x36
    Local $opad = Binary(''), $ipad = Binary('')
    $key = Binary($key)
    If BinaryLen($key) > $blocksize Then $key = Call($hash, $key)
    For $i = 1 To BinaryLen($key)
        $a_ipad[$i-1] = Number(BinaryMid($key, $i, 1))
        $a_opad[$i-1] = Number(BinaryMid($key, $i, 1))
    Next
    For $i = 0 To $blocksize - 1
        $a_opad[$i] = BitXOR($a_opad[$i], $oconst)
        $a_ipad[$i] = BitXOR($a_ipad[$i], $iconst)
    Next
    For $i = 0 To $blocksize - 1
        $ipad &= Binary('0x' & Hex($a_ipad[$i],2))
        $opad &= Binary('0x' & Hex($a_opad[$i],2))
    Next
    Return Call($hash, $opad & Call($hash, $ipad & Binary($message)))
EndFunc

ConsoleWrite(hmac("key", "the", "sha1") & @CRLF)

 

Edit: Firefox ate my post, had to fix...

 

On 02.11.2012 at 11:02 PM, jchd said:

Some points for you to look at:

o) RC4 ≠ XOR

o) You seem to be confusing operation on strings and binary data. Look at you filled key: it should be a binary conatining the binary for 'key' appended with binary zeroes, not the character 0. Same for '5C' and '36'.

 

Once you change your code to perform on all binary data, I bet mud will clear a bit.

ts for you to look at:

o) RC4 ≠ XOR

o) You seem to be confusing operation on strings and binary data. Look at you filled key: it should be a binary conatining the binary for 'key' appended with binary zeroes, not the character 0. Same for '5C' and '36'.

 

Once you change your code to perform on all binary data, I bet mud will clear a bit.

GUYS I NEED YOUR HELP I  dont know how to convert this line of code from php to autoit I know that you are the only one who can help me

$hmacsignature =hash_hmac("sha256", $signature, base64_decode( $API_SECRET ));

Share this post


Link to post
Share on other sites
BrewManNH

You've posted this question at least 3 times now in 3 different threads, stop already and stick to one thread.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
JLogan3o13

@cezarlacatus As has been mentioned, keep it to one thread.

  • Like 2

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
cezarlacatus

Guys i am sorry...i didnt know that i could not close threats...

Share this post


Link to post
Share on other sites
cezarlacatus
2 hours ago, Earthshine said:

have you checked the help file? is this link of any use?

 

No....i cant use it ; i am so sad...seems that nobody want to implement this feature....

Share this post


Link to post
Share on other sites
JLogan3o13

Why does that thread not work for you? You state "I can't use it", what does that mean? What did you try and what did not work for you? Please be aware that this forum is dedicated to helping people improve their own scripts; it is not a place where you put in a request and someone does all the work for you. If you're encountering issues you need to:

  • Explain in detail what you have tried, and what is not working.
  • Like 1

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Jos

@cezarlacatus,

You are really pushing it around here when I see your brief history in our forums and finding an PM with a question from you.
I seriously advice you to read those forum rules we have around here before we feel the need to stop you impatience forcefully.
Welcome by the way. ;) 

Jos
 


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Earthshine

I seriously thought this was the answer he sought. The code in that post specifically.

 


My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
cezarlacatus
26 minutes ago, Earthshine said:

I seriously thought this was the answer he sought. The code in that post specifically.

 

Yes that encrypts data with md5.I need to encrypt data with sha256 and a password or something like that.I found a post but their scripts are using sha1 or anithing else but they are the base structure...i understend nothing from them

 

 

Share this post


Link to post
Share on other sites
cezarlacatus
41 minutes ago, Jos said:

@cezarlacatus,

You are really pushing it around here when I see your brief history in our forums and finding an PM with a question from you.
I seriously advice you to read those forum rules we have around here before we feel the need to stop you impatience forcefully.
Welcome by the way. ;) 

Jos
 

I am really sorry i wanted to lock my previous post and re-start a thread with the main problem ...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • DeltaRocked
      By DeltaRocked
      [solution SkinnyWhiteGuy]



      Hi,

      I have been trying to work with HMAC-SHA1 for oAuth, as it is the base requirement for generating the oAuth Signature.

      According to the definition http://en.wikipedia.org/wiki/Hash-based_message_authentication_code

      Definition (from RFC 2104)
      HMAC (K,m) = H ((K ^ opad) || H ((K ^ ipad) || m))
      where
      H is a cryptographic hash function,
      K is a secret key padded to the right with extra zeros to the input block size of the hash function, or the hash of the original key if it's longer than that block size,
      m is the message to be authenticated,
      || denotes concatenation,
      ^ denotes exclusive or (XOR),
      opad is the outer padding (0x5c5c5c…5c5c, one-block-long hexadecimal constant),
      and ipad is the inner padding (0x363636…3636, one-block-long hexadecimal constant).

      Since this is XOR of two strings I have used _StringEncrypt = RC4 = XOR two strings.

      However, somewhere I am making a mistake and I getting a different result.

      Need Help.

      Regards

      #include <Crypt.au3> #include <String.au3> $message = 'the' $key = 'key' $key = key_fill($key) ConsoleWrite('Key = ' & $key & @CRLF) $opad = '0x'&_StringEncrypt(1, $key, padfill('5c', 64)) ConsoleWrite('Opad = ' & $opad & @CRLF) $ipad = '0x'&_StringEncrypt(1, $key, padfill('36', 64)) ConsoleWrite('Ipad = ' & $ipad & @CRLF) $val = _Crypt_HashData($opad & _Crypt_HashData($ipad & $message, $CALG_SHA1), $CALG_SHA1) ConsoleWrite('OutPut Hash = ' & StringLower($val) & @CRLF) ConsoleWrite(@CRLF & 'HMAC SHA1 from website http://caligatio.github.com/jsSHA/ ' & @CRLF _ & 'Input = the ' & @CRLF _ & 'Key = key ' & @CRLF _ & 'OutPut Hash = 0xe2bd5b5373d0602ec959cac3f83f5d1714744853' & @CRLF) Func key_fill($keyfill) If StringLen($keyfill) < 64 Then While StringLen($keyfill) < 64 $keyfill &= 0 WEnd Else $keyfill = _Crypt_HashData($keyfill, $CALG_SHA1) EndIf Return $keyfill EndFunc ;==>key_fill Func padfill($pad, $blocksize) Local $i = 1, $retpad While $i <= 64 $retpad &= $pad $i += 1 WEnd ConsoleWrite($retpad &@CRLF) Return $retpad EndFunc ;==>padfill
      The OutPut

      Key = key0000000000000000000000000000000000000000000000000000000000000 5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c Opad = 0x0B1BACB78CAE03D70B6993DC7F377E24B4C57CF4B51C5C2A875A71245C691C452FF81ED75B9AF81DB15C112E654AF8EA685F8B2F95CEA2B3D8FD6BE4680289B4DC589D2016184697A58E098608F80384BE7446FA95EE8B6AF7EEC332E051B021F10B49CF32110F3B9918FE704AA8C22A6C955F5A99370C184408185FD8982BAE 36363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636 Ipad = 0x159D405E7F0A5237C2810038FCBA216A4366FF99482CDD115D775BD0554F2A74457E227429511135CD511F6707A2BDD8C2FF3B2774FEAF59B1CB0258152204D66A475319B56793A82968090D19A0DE6FD9C2E7C52CBB759D7E6EC4231976A9363E99928F21EE2F8B31F101277CE935E7B0F62779126A528974208ABFF004060C OutPut Hash = 0x8aa82e26740e55c7185f04432d82f064bf41e442 HMAC SHA1 from website http://caligatio.github.com/jsSHA/ Input = the Key = key OutPut Hash = 0xe2bd5b5373d0602ec959cac3f83f5d1714744853
×