Jump to content

5582

Members
  • Posts

    3
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

5582's Achievements

Seeker

Seeker (1/7)

3

Reputation

  1. The problem has been solved, thank you very much to this friend. Danyfirex https://www.autoitscript.com/forum/profile/71248-danyfirex/ At the same time, share the code, and if there are other friends who need it, they can refer to and learn from it. Local $sSecret = "b8pW9XRUxIDdapjpLcjFte" Local $iTimeStamp= 1705638000 ConsoleWrite("HMAC-SHA256: " & @TAB & @TAB & _HashHMAC($sSecret,$iTimeStamp) & @CRLF) Func _HashHMAC($sSecret,$TimeStamp) Local $oHashHMACErrorHandler = ObjEvent("AutoIt.Error", "_HashHMACErrorHandler") Local $oHMAC = ObjCreate("System.Security.Cryptography.HMACSHA256") If @error Then SetError(1, 0, "") Local $sStrToSign =StringFormat("%s\n%s",$TimeStamp,$sSecret) $oHMAC.key = Binary($sStrToSign) Local $bHash = $oHMAC.ComputeHash_2(Binary("")) Return _Base64Encode($bHash) EndFunc ;==>_HashHMAC Func _Base64Encode($input) $input = Binary($input) Local $struct = DllStructCreate("byte[" & BinaryLen($input) & "]") DllStructSetData($struct, 1, $input) Local $strc = DllStructCreate("int") Local $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($struct), _ "int", DllStructGetSize($struct), _ "int", 1, _ "ptr", 0, _ "ptr", DllStructGetPtr($strc)) If @error Or Not $a_Call[0] Then Return SetError(1, 0, "") ; error calculating the length of the buffer needed EndIf Local $a = DllStructCreate("char[" & DllStructGetData($strc, 1) & "]") $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($struct), _ "int", DllStructGetSize($struct), _ "int", 1, _ "ptr", DllStructGetPtr($a), _ "ptr", DllStructGetPtr($strc)) If @error Or Not $a_Call[0] Then Return SetError(2, 0, ""); error encoding EndIf Return DllStructGetData($a, 1) EndFunc ;==>_Base64Encode Func _HashHMACErrorHandler($oError) ;Dummy Error Handler EndFunc ;==>_HashHMACErrorHandler
  2. Thanks. In this webpage, the HmacSHA256 algorithm is needed to calculate the signature. However, I have searched a lot of information online, and both the content value and the KEY value need to be entered. However, in this algorithm signature, it seems that only one content value was entered without seeing the key value. I am not sure what is going on, and I hope to get an answer. Meanwhile, I hope to implement it using autoit3 code https://open.feishu.cn/document/client-docs/bot-v3/add-custom-bot
  3. Can the following Python code be converted to autoit3? Is there any expert who can help me? Thank you. import hashlib import base64 import hmac def gen_sign(timestamp, secret): string_to_sign = '{}\n{}'.format(timestamp, secret) hmac_code = hmac.new(string_to_sign.encode("utf-8"), digestmod=hashlib.sha256).digest() sign = base64.b64encode(hmac_code).decode('utf-8') return sign
×
×
  • Create New...