taurus905 Posted April 2, 2023 Posted April 2, 2023 Hello All, When I use _Crypt_HashData to hash the following using SHA256, the output matches online tools when the input is treated as Text: Input: 2625E615A69CB0B897EE8685022F9710F1BE324612B4907F557548EB3D189925 Output (Input Type set as Text): 0xEEA4F4D06EF446D2BD14769B9BDD98C5C529DE05FDD5898CB20D46C1B0ED25A1 (AutoIt) eea4f4d06ef446d2bd14769b9bdd98c5c529de05fdd5898cb20d46c1b0ed25a1 (online tool) However, when I change the input type from Text to Hex in the online tools, I get the following: Output (Input Type set as Hex): f9f2ffed12040e8153d4bd8964c9e811500db96313702a2ec116f48a08621f0d (online tool) It's my hope I am missing something very simple in AutoIt to get the above output. Thank you to anyone who tries to point me in the right direction. taurus905 "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs
Solution argumentum Posted April 2, 2023 Solution Posted April 2, 2023 1 hour ago, taurus905 said: However, expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.15.5 (Beta) Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <ComboConstants.au3> #include <Crypt.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StringConstants.au3> #include <WinAPIConv.au3> #include <WindowsConstants.au3> Global $g_iAlgorithm = $CALG_SHA_256, $g_idInputEdit = -1, $g_idOutputEdit = -1 Example() Func Example() Local $hGUI = GUICreate("Realtime Hashing", 400, 320) $g_idInputEdit = GUICtrlCreateEdit("", 0, 0, 400, 150, $ES_WANTRETURN) $g_idOutputEdit = GUICtrlCreateEdit("", 0, 150, 400, 150, $ES_READONLY) Local $idCombo = GUICtrlCreateCombo("", 0, 300, 100, 20, $CBS_DROPDOWNLIST) GUICtrlSetData($idCombo, "MD2 (128bit)|MD4 (128bit)|MD5 (128bit)|SHA1 (160bit)|SHA_256|SHA_384|SHA_512", "SHA_256") GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState(@SW_SHOW, $hGUI) _Crypt_Startup() ; To optimize performance start the crypt library. Local $dHash = 0, _ $sRead = BinaryToString("0x2625E615A69CB0B897EE8685022F9710F1BE324612B4907F557548EB3D189925") GUICtrlSetData($g_idInputEdit, $sRead) $dHash = _Crypt_HashData($sRead, $g_iAlgorithm) ; Create a hash of the text entered. GUICtrlSetData($g_idOutputEdit, $dHash) ; Set the output box with the hash data. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idCombo ; Check when the combobox is selected and retrieve the correct algorithm. Switch GUICtrlRead($idCombo) ; Read the combobox selection. Case "MD2 (128bit)" $g_iAlgorithm = $CALG_MD2 Case "MD4 (128bit)" $g_iAlgorithm = $CALG_MD4 Case "MD5 (128bit)" $g_iAlgorithm = $CALG_MD5 Case "SHA1 (160bit)" $g_iAlgorithm = $CALG_SHA1 Case "SHA_256" $g_iAlgorithm = $CALG_SHA_256 Case "SHA_384" $g_iAlgorithm = $CALG_SHA_384 Case "SHA_512" $g_iAlgorithm = $CALG_SHA_512 EndSwitch $sRead = GUICtrlRead($g_idInputEdit) If StringStripWS($sRead, $STR_STRIPALL) <> "" Then ; Check there is text available to hash. $dHash = _Crypt_HashData($sRead, $g_iAlgorithm) ; Create a hash of the text entered. GUICtrlSetData($g_idOutputEdit, $dHash) ; Set the output box with the hash data. EndIf EndSwitch WEnd GUIDelete($hGUI) ; Delete the previous GUI and all controls. _Crypt_Shutdown() ; Shutdown the crypt library. EndFunc ;==>Example Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $lParam Switch _WinAPI_LoWord($wParam) Case $g_idInputEdit Switch _WinAPI_HiWord($wParam) Case $EN_CHANGE Local $dHash = _Crypt_HashData(GUICtrlRead($g_idInputEdit), $g_iAlgorithm) ; Create a hash of the text entered. GUICtrlSetData($g_idOutputEdit, $dHash) ; Set the output box with the hash data. EndSwitch EndSwitch EndFunc ;==>WM_COMMAND ..you're welcome taurus905 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
taurus905 Posted April 3, 2023 Author Posted April 3, 2023 @argumentum VERY NICE!!! I knew it had to do with the datatype and tried all I could think of. But not "BinaryToString" while including the "0x" prefix. Thank you for taking the time. You made my day. taurus905 argumentum 1 "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now