如何在 AHK Windows 10 中生成字符串的 MD5? [英] How do I generate MD5 of a string in AHK Windows 10?

查看:83
本文介绍了如何在 AHK Windows 10 中生成字符串的 MD5?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了 https://github.com/acmeism/RosettaCodeData/blob/master/Task/MD5/AutoHotkey/md5-1.ahk确实适用于 Windows 7:

I tried the code from https://github.com/acmeism/RosettaCodeData/blob/master/Task/MD5/AutoHotkey/md5-1.ahk, which did work with windows 7:

data := "abc"
MsgBox % MD5(data,StrLen(data)) ; 900150983cd24fb0d6963f7d28e17f72

MD5( ByRef V, L=0 ) {
 VarSetCapacity( MD5_CTX,104,0 ), DllCall( "advapi32\MD5Init", Str,MD5_CTX )
 DllCall( "advapi32\MD5Update", Str,MD5_CTX, Str,V, UInt,L ? L : VarSetCapacity(V) )
 DllCall( "advapi32\MD5Final", Str,MD5_CTX )
 Loop % StrLen( Hex:="123456789ABCDEF0" )
  N := NumGet( MD5_CTX,87+A_Index,"Char"), MD5 .= SubStr(Hex,N>>4,1) . SubStr(Hex,N&15,1)
Return MD5
}

但是,某些 dll 调用现在必须无法正常工作,因为它不会返回正确的值与 Windows 10.例如,给定的代码片段返回 70350F6027BCE3713F6B76473084309B而不是 900150983cd24fb0d6963f7d28e17f72.我也尝试以管理员权限运行它.不知道这背后的原因是什么.由于某种原因,我无法直接访问 advapi32 dll 中的 MD5 函数.

However, some dll calls must be non-functional now, since it does not return the right values with windows 10. For example, the given code snippet returns 70350F6027BCE3713F6B76473084309B instead of 900150983cd24fb0d6963f7d28e17f72. I also tried running it with administrator rights. Not sure what is the reason behind this. I haven't been able to access the MD5-functions in the advapi32 dll directly, for some reason.

我应该怎么做才能获得正确的 MD5 哈希值?

What should I do to get a correct MD5 hash?

推荐答案

这些来自 jNizM 的哈希函数似乎有效:https://www.autohotkey.com/boards/viewtopic.php?f=6&t=21

These hash functions from jNizM seem to work: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=21

对于 MD5:

md5(string)     ;   // by SKAN | rewritten by jNizM
{
    hModule := DllCall("LoadLibrary", "Str", "advapi32.dll", "Ptr")
    , VarSetCapacity(MD5_CTX, 104, 0), DllCall("advapi32\MD5Init", "Ptr", &MD5_CTX)
    , DllCall("advapi32\MD5Update", "Ptr", &MD5_CTX, "AStr", string, "UInt", StrLen(string))
    , DllCall("advapi32\MD5Final", "Ptr", &MD5_CTX)
    loop, 16
        o .= Format("{:02" (case ? "X" : "x") "}", NumGet(MD5_CTX, 87 + A_Index, "UChar"))
    DllCall("FreeLibrary", "Ptr", hModule)
    StringLower, o,o
    return o
}

这篇关于如何在 AHK Windows 10 中生成字符串的 MD5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆