本帖最后由 oceanwind 于 2021-12-26 22:31 编辑
源码链接Hash HMAC - AutoIt Example Scripts - AutoIt Forums (autoitscript.com)Local $sSecret = "SecretKey"
Local $sMessage = "AutoIt Rocks!!!"
ConsoleWrite("HMAC-SHA256: " & @TAB & @TAB & _HashHMAC("SHA512", $sMessage, $sSecret) & @CRLF)
ConsoleWrite("HMAC-SHA256: " & @TAB & @TAB & _HashHMAC("SHA256", $sMessage, $sSecret) & @CRLF)
ConsoleWrite("HMAC-SHA1: " & @TAB & @TAB & _HashHMAC("SHA1", $sMessage, $sSecret) & @CRLF)
ConsoleWrite("HMAC-SHA384: " & @TAB & @TAB & _HashHMAC("SHA384", $sMessage, $sSecret) & @CRLF)
ConsoleWrite("HMAC-MD5: " & @TAB & @TAB & _HashHMAC("MD5", $sMessage, $sSecret) & @CRLF)
ConsoleWrite("HMAC-RIPEMD160: " & @TAB & _HashHMAC("RIPEMD160", $sMessage, $sSecret) & @CRLF)
Func _HashHMAC($sAlgorithm, $bData, $bKey, $bRaw_Output = False)
Local $oHashHMACErrorHandler = ObjEvent("AutoIt.Error", "_HashHMACErrorHandler")
Local $oHMAC = ObjCreate("System.Security.Cryptography.HMAC" & $sAlgorithm)
If @error Then SetError(1, 0, "")
$oHMAC.key = Binary($bKey)
Local $bHash = $oHMAC.ComputeHash_2(Binary($bData))
Return SetError(0, 0, $bRaw_Output ? $bHash : StringLower(StringMid($bHash, 3)))
EndFunc ;==>_HashHMAC
Func _HashHMACErrorHandler($oError)
;Dummy Error Handler
EndFunc ;==>_HashHMACErrorHandler
返回的值对应python的HMAC.NEW(key,data,SHA-256).hexdigest(),如何修改以返回二进制的值,对应python的HMAC.NEW(key,data,SHA-256).digest().
请朋友们指点,谢谢先。
|