MD5 16位是32位截取的
SubStr(md5,9,16)
HashFromAddr(pData, len, algid, key=0) { hProv := size := hHash := hash := "" ptr := (A_PtrSize) ? "ptr" : "uint" aw := (A_IsUnicode) ? "W" : "A" if (DllCall("advapi32\CryptAcquireContext" aw, ptr "*", hProv, ptr, 0, ptr, 0, "uint", 1, "uint", 0xF0000000)) { if (DllCall("advapi32\CryptCreateHash", ptr, hProv, "uint", algid, "uint", key, "uint", 0, ptr "*", hHash)) { if (DllCall("advapi32\CryptHashData", ptr, hHash, ptr, pData, "uint", len, "uint", 0)) { if (DllCall("advapi32\CryptGetHashParam", ptr, hHash, "uint", 2, ptr, 0, "uint*", size, "uint", 0)) { VarSetCapacity(bhash, size, 0) DllCall("advapi32\CryptGetHashParam", ptr, hHash, "uint", 2, ptr, &bhash, "uint*", size, "uint", 0) } } DllCall("advapi32\CryptDestroyHash", ptr, hHash) } DllCall("advapi32\CryptReleaseContext", ptr, hProv, "uint", 0) } int := A_FormatInteger SetFormat, Integer, h Loop, % size { v := substr(NumGet(bhash, A_Index-1, "uchar") "", 3) while (strlen(v)<2) v := "0" v hash .= v } SetFormat, Integer, % int return hash } HashFromString(string, algid, key=0) { len := strlen(string) if (A_IsUnicode) { ;VarSetCapacity(data, len) ;StrPut(string, &data, len, "cp0") return HashFromAddr(&data, len, algid, key) } data := string return HashFromAddr(&data, len, algid, key) } MD5(string,b16:=false) { ;0x8003/*_CALG_MD5*/ ;0x8001/*_CALG_MD2*/ ;0x8002/*_CALG_MD4*/ ;0x8004/*_CALG_SHA1*/ return b16 ? SubStr(HashFromString(string, 0x8003),9,16) : HashFromString(string, 0x8003) } MsgBox % md5(Ansi2UTF8("我们"),1)
60 queries in 1.626 seconds |