以指定算法散列化数据
#Include <Crypt.au3>
_Crypt_HashData($vData, $iALG_ID [, $fFinal = True [, $hCryptHash = 0]])
$vData | 要散列化的数据 |
$iALG_ID | 使用的散列化标识 |
$fFinal | [可选参数] 设置为 False, 表明只是全部数据的一部分, 同时使该函数返回一个对象而不是 Hash |
$hCryptHash | [可选参数] 先前调用 _Crypt_HashData 函数返回的 Hash 对象 |
成功: | 返回 Hash , 如果设置 $fFinal = False, 则返回 Hash 对象 |
设置 @error 为 0 | |
失败: | 返回 -1 并设置 @error: |
1 - 无法创建 hash 对象 | |
2 - 无法 Hash 数据 | |
3 - 无法取得 Hash 大小 | |
4 - 无法获取 Hash |
在MSDN中搜索
#include <Crypt.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Global $bAlgorithm = $CALG_SHA1, $iInputEdit = -1, $iOutputEdit = -1
GUICreate("Realtime Hashing", 400, 320)
$iInputEdit = GUICtrlCreateEdit("", 0, 0, 400, 150, $ES_WANTRETURN)
$iOutputEdit = GUICtrlCreateEdit("", 0, 150, 400, 150, $ES_READONLY)
Local $iCombo = GUICtrlCreateCombo("", 0, 300, 100, 20, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "MD2|MD4|MD5|SHA1", "SHA1")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUISetState(@SW_SHOW)
_Crypt_Startup() ; To optimize performance start the crypt library.
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $iCombo ; Check when the combobox is selected and retrieve the correct algorithm.
Switch GUICtrlRead($iCombo) ; Read the combobox selection.
Case "MD2"
$bAlgorithm = $CALG_MD2
Case "MD4"
$bAlgorithm = $CALG_MD4
Case "MD5"
$bAlgorithm = $CALG_MD5
Case "SHA1"
$bAlgorithm = $CALG_SHA1
EndSwitch
Local $sRead = GUICtrlRead($iInputEdit)
If StringStripWS($sRead, 8) <> "" Then ; Check there is text available to hash.
Local $bHash = _Crypt_HashData($sRead, $bAlgorithm) ; Create a hash of the text entered.
GUICtrlSetData($iOutputEdit, $bHash) ; Set the output box with the hash data.
EndIf
EndSwitch
WEnd
_Crypt_Shutdown() ; Shutdown the crypt library.
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $lParam
Switch _WinAPI_LoWord($wParam)
Case $iInputEdit
Switch _WinAPI_HiWord($wParam)
Case $EN_CHANGE
Local $bHash = _Crypt_HashData(GUICtrlRead($iInputEdit), $bAlgorithm) ; Create a hash of the text entered.
GUICtrlSetData($iOutputEdit, $bHash) ; Set the output box with the hash data.
EndSwitch
EndSwitch
EndFunc ;==>WM_COMMAND