#NoTrayIcon #include #include #include #include #include #include #include #include Local $hInput[4], $hOutput, $hCombo Example() Func Example() Local $hGUI, $btnDerive, $btnCopy, $msg ; Create GUI $hGUI = GUICreate("PBKDF2 Key Derivation", 400, 320) ; Create labels GUICtrlCreateLabel("Password:", 10, 10, 60, 20) GUICtrlCreateLabel("Salt:", 10, 40, 60, 20) GUICtrlCreateLabel("Iterations:", 10, 70, 60, 20) GUICtrlCreateLabel("Key Length:", 10, 100, 60, 20) ; Create input fields $hInput[0] = GUICtrlCreateInput("", 80, 10, 310, 20) $hInput[1] = GUICtrlCreateInput("", 80, 40, 310, 20) $hInput[2] = GUICtrlCreateInput("", 80, 70, 310, 20) $hInput[3] = GUICtrlCreateInput("", 80, 100, 310, 20) ; Create Derive button $btnDerive = GUICtrlCreateButton("Derive Key", 10, 130, 80, 30) ; Create Hash Algorithm combo box $hCombo = GUICtrlCreateCombo("", 280, 130, 110, 20, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL)) GUICtrlSetData($hCombo, "SHA1 (160bit)|SHA256 (256bit)|SHA384 (384bit)|SHA512 (512bit)|MD2 (128bit)|MD4 (128bit)|MD5 (128bit)") GUICtrlSetData($hCombo, "SHA256 (256bit)", "SHA256 (256bit)") ; Define SHA256 como selecionado ; Create output area $hOutput = GUICtrlCreateEdit("", 10, 170, 380, 100, BitOR($ES_READONLY, $ES_AUTOVSCROLL, $ES_WANTRETURN)) GUICtrlSetFont($hOutput, 9, 400, 0, "Courier New") ; Definir a fonte monoespaƧada ; Create Copy button $btnCopy = GUICtrlCreateButton("Copy", 10, 280, 80, 30) ; Show GUI GUISetState(@SW_SHOW) ; Event loop While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case $btnDerive OnDeriveClick() Case $btnCopy OnCopyClick() EndSwitch WEnd ; Close the GUI GUIDelete($hGUI) EndFunc Func OnDeriveClick() Local $password, $salt, $iterations, $keyLength, $derivedKey, $algorithm ; Get input values $password = GUICtrlRead($hInput[0]) $salt = GUICtrlRead($hInput[1]) $iterations = GUICtrlRead($hInput[2]) $keyLength = GUICtrlRead($hInput[3]) ; Get selected algorithm $algorithm = GUICtrlRead($hCombo) Switch $algorithm Case "SHA1 (160bit)" $algorithm = $CNG_BCRYPT_SHA1_ALGORITHM Case "SHA256 (256bit)" $algorithm = $CNG_BCRYPT_SHA256_ALGORITHM Case "SHA384 (384bit)" $algorithm = $CNG_BCRYPT_SHA384_ALGORITHM Case "SHA512 (512bit)" $algorithm = $CNG_BCRYPT_SHA512_ALGORITHM Case "MD2 (128bit)" $algorithm = $CNG_BCRYPT_MD2_ALGORITHM Case "MD4 (128bit)" $algorithm = $CNG_BCRYPT_MD4_ALGORITHM Case "MD5 (128bit)" $algorithm = $CNG_BCRYPT_MD5_ALGORITHM EndSwitch ; Call PBKDF2 example function $derivedKey = pbkdf2_example($password, $salt, $iterations, $keyLength, $algorithm) ; Remove "0x" from the beginning of the derived key If StringLeft($derivedKey, 2) = "0x" Then $derivedKey = StringTrimLeft($derivedKey, 2) EndIf ; Convert derived key to lowercase $derivedKey = StringLower($derivedKey) ; Set output GUICtrlSetData($hOutput, $derivedKey) EndFunc Func pbkdf2_example($password, $salt, $iterations, $keyLength, $algorithm) Local $xPasswordHash = "" ; PBKDF2 Example $xPasswordHash = _CryptoNG_PBKDF2($password, $salt, $iterations, $keyLength * 8, $algorithm) If @error Then ConsoleWrite("ERROR: " & _CryptoNG_LastErrorMessage() & @CRLF) Return "" EndIf Return $xPasswordHash EndFunc Func OnCopyClick() ; Copy output to clipboard ClipPut(GUICtrlRead($hOutput)) EndFunc