lpxx 发表于 2018-10-30 20:54:45

有可能是au3获取MD5最简单的方法了

本帖最后由 lpxx 于 2018-10-30 20:58 编辑

有可能是au3获取MD5最简单的方法了,支持中文。MsgBox(0, "MD5", _MD5("test"))
Func _MD5($string)
      Static Local $hDLL = DllOpen("advapi32.dll")
      Static Local $MD5_CTX = DllStructCreate("dword i;dword buf;ubyte in;ubyte digest")
      DllCall($hDLL, "none", "MD5Init", "ptr", DllStructGetPtr($MD5_CTX))
      DllCall($hDLL, "none", "MD5Update", "ptr", DllStructGetPtr($MD5_CTX), "str", $string, "dword", StringLen($string))
      DllCall($hDLL, "none", "MD5Final", "ptr", DllStructGetPtr($MD5_CTX))
      Return Hex(DllStructGetData($MD5_CTX, "digest"))
EndFunc   ;==>_MD5

lpxx 发表于 2018-11-5 20:35:22

chishingchan 发表于 2018-11-2 19:34
有没有针对文件的而不是字符串?

大概这个样子
Global $sFile
Global $gui00 = GUICreate(" ", 325, 150, -1, -1)
Global $inp01 = GUICtrlCreateInput("", 35, 25, 250, 20)
Global $inp02 = GUICtrlCreateInput("", 35, 70, 250, 20)
Global $btn01 = GUICtrlCreateButton("打开文件", 20, 115, 70, 25)
Global $btn02 = GUICtrlCreateButton("复制", 125, 115, 70, 25)
Global $btn03 = GUICtrlCreateButton("退出", 230, 115, 70, 25)
GUISetState(@SW_SHOW, $gui00)
;
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3, $btn03
                        ExitLoop
                Case $btn01
                        $sFile = FileOpenDialog("选择文件", @ScriptDir, "All Files (*.*)", 1)
                        If $sFile Then
                                GUICtrlSetData($inp01, $sFile)
                                GUICtrlSetData($inp02, _MD5($sFile))
                        Else
                                ContinueLoop
                        EndIf
                Case $btn02
                        ClipPut(GUICtrlRead($inp02))
        EndSwitch
WEnd
GUIDelete($gui00)
Exit

Func _MD5($string)
      Static Local $hDLL = DllOpen("advapi32.dll")
      Static Local $MD5_CTX = DllStructCreate("dword i;dword buf;ubyte in;ubyte digest")
      DllCall($hDLL, "none", "MD5Init", "ptr", DllStructGetPtr($MD5_CTX))
      DllCall($hDLL, "none", "MD5Update", "ptr", DllStructGetPtr($MD5_CTX), "str", $string, "dword", StringLen($string))
      DllCall($hDLL, "none", "MD5Final", "ptr", DllStructGetPtr($MD5_CTX))
      Return Hex(DllStructGetData($MD5_CTX, "digest"))
EndFunc   ;==>_MD5


lpxx 发表于 2018-10-30 20:55:20

SHA的方法MsgBox(0, "SHA", _SHA("test"))

Func _SHA($string)
        Static Local $hDLL = DllOpen("advapi32.dll")
        Static Local $SHA_CTX = DllStructCreate("dword unknown;dword state;dword count;ubyte buffer;ubyte digest")
        DllCall($hDLL, "none", "A_SHAInit", "ptr", DllStructGetPtr($SHA_CTX))
        DllCall($hDLL, "none", "A_SHAUpdate", "ptr", DllStructGetPtr($SHA_CTX), "str", $string, "dword", StringLen($string))
        DllCall($hDLL, "none", "A_SHAFinal", "ptr", DllStructGetPtr($SHA_CTX), "ptr", DllStructGetPtr($SHA_CTX) + 0x74)
        Return Hex(DllStructGetData($SHA_CTX, "digest"))
EndFunc   ;==>_SHA

lpxx 发表于 2018-10-30 20:55:51

本帖最后由 lpxx 于 2018-12-9 19:13 编辑

MD4的方法
MsgBox(0, "MD4", _MD4("test"))
Func _MD4($string)
      Static Local $hDLL = DllOpen("advapi32.dll")
      Static Local $MD4_CTX = DllStructCreate("dword i;dword buf;ubyte in;ubyte digest")
      DllCall($hDLL, "none", "MD4Init", "ptr", DllStructGetPtr($MD4_CTX))
      DllCall($hDLL, "none", "MD4Update", "ptr", DllStructGetPtr($MD4_CTX), "str", $string, "dword", StringLen($string))
      DllCall($hDLL, "none", "MD4Final", "ptr", DllStructGetPtr($MD4_CTX))
      Return Hex(DllStructGetData($MD4_CTX, "digest"))
EndFunc   ;==>_MD4


Base64的方法
$encoded = _Base64Encode("Autoit3.cn")
MsgBox(0, 'Base64 Encoded', $encoded)

$decoded = _Base64Decode($encoded)
MsgBox(0, 'Base64解码 - 二进制', $decoded)
MsgBox(0, 'Base64解码 - 字符串', BinaryToString($decoded))

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 Then
      Return SetError(1, 0, "")
    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 Then
      Return SetError(2, 0, "")
    EndIf
    Return DllStructGetData($a, 1)
EndFunc   ;==>_Base64Encode

Func _Base64Decode($input_string)
    Local $struct = DllStructCreate("int")
    $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $input_string, "int", 0, "int", 1, "ptr", 0, "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0)
    If @error Or Not $a_Call Then
      Return SetError(1, 0, "")
    EndIf
    Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]")
    $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $input_string, "int", 0, "int", 1, "ptr", DllStructGetPtr($a), "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0)
    If @error Or Not $a_Call Then
      Return SetError(2, 0, "")
    EndIf
    Return DllStructGetData($a, 1)
EndFunc   ;==>_Base64Decode


hnfeng 发表于 2018-10-31 08:21:12

赞一个,谢谢分享

229989799 发表于 2018-10-31 08:31:38

thanks for share..

redapple2008 发表于 2018-10-31 10:00:21

不错,好方法,谢谢了

xzf680 发表于 2018-10-31 11:01:54

收藏一下,这个好

449199199 发表于 2018-10-31 11:25:37

看楼主签名就知道人很大方~~

229989799 发表于 2018-10-31 14:22:01

留下脚印,以后查找

hjq766 发表于 2018-10-31 15:02:05

感谢楼主分享~

duxing 发表于 2018-11-1 09:10:56

收藏一下,终于看到实用又不收费的了

881966 发表于 2018-11-2 19:15:24

学习一下,谢谢分享

chishingchan 发表于 2018-11-2 19:34:59

有没有针对文件的而不是字符串?

wkun 发表于 2018-11-3 12:51:53

钱是个东西啊,为啥 不收点费呢。{:face (316):}
页: [1] 2
查看完整版本: 有可能是au3获取MD5最简单的方法了