oceanwind 发表于 2021-12-26 12:29:25

[已解决]这个HMAC_SHA256函数返回值如何返回是二进制值

本帖最后由 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().
请朋友们指点,谢谢先。

life999 发表于 2021-12-26 13:16:56

我来看看看啊

oceanwind 发表于 2021-12-26 20:07:07

英文论坛有朋友回复了 https://www.autoitscript.com/forum/topic/207244-how-to-get-binary-result-from-hmac-sha256-user-defined-function/
页: [1]
查看完整版本: [已解决]这个HMAC_SHA256函数返回值如何返回是二进制值