找回密码
 加入
搜索
查看: 8382|回复: 18

[原创] 有可能是au3获取MD5最简单的方法了

  [复制链接]
发表于 2018-10-30 20:54:45 | 显示全部楼层 |阅读模式
本帖最后由 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[2];dword buf[4];ubyte in[64];ubyte digest[16]")
        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
 楼主| 发表于 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[2];dword buf[4];ubyte in[64];ubyte digest[16]")
        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

评分

参与人数 1威望 +2 金钱 +50 贡献 +10 收起 理由
chishingchan + 2 + 50 + 10 赞一个!

查看全部评分

 楼主| 发表于 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[6];dword state[5];dword count[2];ubyte buffer[64];ubyte digest[20]")
        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
 楼主| 发表于 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[2];dword buf[4];ubyte in[64];ubyte digest[16]")
        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[0] 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[0] 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[0] 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[0] Then
        Return SetError(2, 0, "")
    EndIf
    Return DllStructGetData($a, 1)
EndFunc   ;==>_Base64Decode

发表于 2018-10-31 08:21:12 | 显示全部楼层
赞一个,谢谢分享
发表于 2018-10-31 08:31:38 | 显示全部楼层
thanks for share..
发表于 2018-10-31 10:00:21 | 显示全部楼层
不错,好方法,谢谢了
发表于 2018-10-31 11:01:54 | 显示全部楼层
收藏一下,这个好
发表于 2018-10-31 11:25:37 | 显示全部楼层
看楼主签名就知道人很大方~~
发表于 2018-10-31 14:22:01 | 显示全部楼层
留下脚印,以后查找
发表于 2018-10-31 15:02:05 | 显示全部楼层
感谢楼主分享~
发表于 2018-11-1 09:10:56 | 显示全部楼层
收藏一下,终于看到实用又不收费的了
发表于 2018-11-2 19:15:24 | 显示全部楼层
学习一下,谢谢分享
发表于 2018-11-2 19:34:59 | 显示全部楼层
有没有针对文件的而不是字符串?
发表于 2018-11-3 12:51:53 | 显示全部楼层
钱是个东西啊,为啥 不收点费呢。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-25 15:08 , Processed in 0.083713 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表