本帖最后由 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
|