Martin_Bauer Posted March 11 Share Posted March 11 Hi all. For an Api call, I need a "secret_key" which is a HMAC using SHA-256 as the cryptographic hash function String. I have got an example python script, the output of it would be correct, and the api endpint would accept the generated String . #Py Code import hmac import hashlib # data (which in reality comes from an INI file) _method = "TestData1" _uri ="TestData2" _body ="" _timestamp="TestData3" _secret_key="TestData4" def sign_request(method, uri, body, timestamp, secret_key): plain_text = "\n".join([method, uri, body, str(timestamp)]) digest_maker = hmac.new(secret_key.encode(), None, hashlib.sha256) digest_maker.update(plain_text.encode()) print (digest_maker.hexdigest()) sign_request(_method,_uri, _body, _timestamp, _secret_key) The output of this code would be : 8d492cf6382fdc4911708be1e2a649d821e7e5ff83b8b3071a46601480770bb9 However since I don't want to run a CMD window to start the Python script ( Comspec , shellexecute, run, does not really work. somehow the python script would Start but not be able to read the Data I left in an INI file , does not matter if starting the .py script or .exe compiled) And I don't want the user to get confused seeing 20 powershell/ Cmd windows, So i wrote it in Autoit, and came up with this: #include <Constants.au3> #include <Crypt.au3> sign_request("TestData1", "TestData2", "", "TestData3", "TestData4") Func sign_request($method, $uri, $body, $timestamp, $secret_key) Local $plain_text = $method & @lf & $uri & @lf & $body & @lf & $timestamp& @lf & $secret_key Local $digest_maker = _Crypt_HashData($plain_text, $CALG_SHA_256, $secret_key) ConsoleWrite($digest_maker & @CRLF) EndFunc but the output of the autoit script is : 3708995A8B8DD39ED1C4B104A0BC2ADE7A8E914F70B2641898AEA39B885B47A7 and not: 8d492cf6382fdc4911708be1e2a649d821e7e5ff83b8b3071a46601480770bb9 I tried changing @lf to @crlf and i am always getting a diffrent outputs, but never the one i need. Maybe someone with more Python and Autoit skills can see or find the mistake I have made in translating the code to Autoit. I have also left a Screenshoot from the Api Documentation where they talk about the "secret_key". Thanks for every help / Input in advance. Link to comment Share on other sites More sharing options...
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
Already have an account? Sign in here.Sign In Now