MattHiggs Posted March 2, 2016 Share Posted March 2, 2016 (edited) I am trying to encrypt and decrypt data a user inputs into a input box using crypt.au3 functions. However, when this is actually run, it returns all "0"s. Can someone please tell me what I am doing wrong? expandcollapse popupGlobal Const $key = _Crypt_DeriveKey ( "KeyToKeepDataSafe", $CALG_AES_256 ) #Region --- CodeWizard generated code Start --- ;InputBox features: Title=Yes, Prompt=Yes, Default Text=No, Mandatory If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer $sInputBoxAnswer = InputBox("Name", "Please enter your first and last name.", "", " M") Select Case @error = 0 $Namearray = StringSplit($sInputBoxAnswer, " ") If $Namearray[0] = 2 And $Namearray[2] <> "" Then IniWrite($storepath, "Name", "First", encry ($Namearray[1])) IniWrite($storepath, "Name", "Last", encry ($Namearray[2])) #Region --- CodeWizard generated code Start --- ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=None MsgBox(0,"data","Encrypt 1: " & encry ($Namearray[1]) & @CRLF & "Encrypt 2: " & encry ($Namearray[2]) & @CRLF & "Decrypt 1: " & decry ( IniRead ( $storepath, "Name", "First", "na" ) ) & @CRLF & "Decrypt 2: " & decry ( IniRead ( $storepath, "Name", "Last", "na" ) )) #EndRegion --- CodeWizard generated code End --- Else #Region --- CodeWizard generated code Start --- ;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Icon=Critical If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox($MB_YESNO + $MB_ICONHAND, "an error occured", "Did you put input your full name separated by space? Do you want to try again?") Select Case $iMsgBoxAnswer = $IDYES names(True) Case $iMsgBoxAnswer = $IDNO $errr = True EndSelect #EndRegion --- CodeWizard generated code Start --- EndIf Case @error = 1 ;The Cancel button was pushed $errr = True Case @error = 3 ;The InputBox failed to open $errr = True EndSelect #EndRegion --- CodeWizard generated code Start --- Func encry ( $input2 ) _Crypt_Startup () _Crypt_EncryptData ( $input2, $key, $CALG_USERKEY ) _Crypt_Shutdown() EndFunc Func decry ( $input ) _Crypt_Startup ( ) _Crypt_DecryptData ( $input, $key, $CALG_USERKEY ) _Crypt_Shutdown () EndFunc Edited March 2, 2016 by MattHiggs Link to comment Share on other sites More sharing options...
MattHiggs Posted March 2, 2016 Author Share Posted March 2, 2016 Just be aware that this is a small snippet out of a massive project I am working on. Everything compile correctly (I do have "#include <Crypt.au3>" in the code, just didn't put in snippet), so I am guessing the problem lies in the area I shared Link to comment Share on other sites More sharing options...
AutoBert Posted March 2, 2016 Share Posted March 2, 2016 (edited) You just forgot to return the result: Func encry($input2) _Crypt_Startup() Local $sRet=_Crypt_EncryptData($input2, $key, $CALG_USERKEY) _Crypt_Shutdown() Return $sRet EndFunc ;==>encry there are also other errors, forgot to include: #include <Crypt.au3> #include <MsgBoxConstants.au3> and here the rest errors: +> SciTEDir => C:\Program Files\AutoIt3\SciTE UserDir => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\Bert\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.2) from:C:\Program Files\AutoIt3 input:C:\Users\Bert\AutoIt3.My\Temp\aa.au3 "C:\Users\Bert\AutoIt3.My\Temp\aa.au3"(13,23) : warning: $storepath: possibly used before declaration. IniWrite($storepath, ~~~~~~~~~~~~~~~~~~~^ "C:\Users\Bert\AutoIt3.My\Temp\aa.au3"(13,23) : error: $storepath: undeclared global variable. IniWrite($storepath, ~~~~~~~~~~~~~~~~~~~^ "C:\Users\Bert\AutoIt3.My\Temp\aa.au3"(28,16) : error: names(): undefined function. names(True) ~~~~~~~~~~^ C:\Users\Bert\AutoIt3.My\Temp\aa.au3 - 2 error(s), 1 warning(s) so i haven't tested. Edited March 2, 2016 by AutoBert Link to comment Share on other sites More sharing options...
MattHiggs Posted March 2, 2016 Author Share Posted March 2, 2016 (edited) Thank you. That certainly did help with getting "0"s as the return. Can't believe I forgot about the return. But like I said, this is a small snippet of a big project. Everything compiles and there are no errors, even if i didn't put all of the code. But on to the new issue. The decrypt function is not returning the original string typed into the input box like it should. I think the IniRead function is returning "na" based on the length of the string returned (which is still encrypted for some reason). So if the IniRead function was reading "na", both decry returns should be the same value. I'm stumped. Any ideas? Code is same as original post with the exception of the return statements added to the encry and decry functions. Edited June 8, 2017 by MattHiggs Link to comment Share on other sites More sharing options...
MattHiggs Posted March 2, 2016 Author Share Posted March 2, 2016 (edited) To make it easier for people to help, here is full function code: expandcollapse popup; *** Start added by AutoIt3Wrapper *** #include <FileConstants.au3> ; *** End added by AutoIt3Wrapper *** #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_SaveSource=y #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator #AutoIt3Wrapper_Add_Constants=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <StaticConstants.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <Constants.au3> #include <Misc.au3> #include <GuiButton.au3> #include <MsgBoxConstants.au3> #include <GuiListBox.au3> #include <GuiListView.au3> #include <Crypt.au3> Global Const $key = _Crypt_DeriveKey ( "KeyToKeepDataSafe", $CALG_AES_256 ) Const $path = @AppDataDir & "\filler" DirCreate($path) FileInstall("C:\Users\whiggs\Onedrive\always script\1_ClipboardHelpAndSpell.ico", @AppDataDir & "\filler\1_ClipboardHelpAndSpell.ico") FileInstall ( "C:\Users\whiggs\OneDrive\always script\relaunch.a3x", $path & "\relaunch.a3x", $FC_OVERWRITE ) If Not FileExists($path & "\formhelp.chm") Then FileInstall("C:\Users\whiggs\OneDrive\formhelp.chm", $path & "\formhelp.chm") EndIf Const $temp = EnvGet("TEMP") $exist = True $storepath = IniRead ( $path & "\infostore.ini", "location", "info", "Not found" ) If $storepath == "Not found" Or FileExists ( $storepath ) = 0 Then #Region --- CodeWizard generated code Start --- ;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Default Button=Second, Icon=None If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox($MB_YESNO + $MB_DEFBUTTON2,"Cannot find Information file",'If this is your first time running the program, select "no" and you will be asked to enter your information. If you have run this program and generated a file containing your information, please select "yes" and open the file.') Select Case $iMsgBoxAnswer = $IDYES $exist = True $file = FileOpenDialog ( "Select your info file here.", @MyDocumentsDir, "Ini File (*.ini)", 3, "login.ini" ) If $file == "" Then Exit EndIf IniWrite ( $path & "\infostore.ini", "location", "info", $file ) $storepath = IniRead ( $path & "\infostore.ini", "location", "info", "Not found" ) Case $iMsgBoxAnswer = $IDNO $exist = False $file = FileSaveDialog ( "create your file", @MyDocumentsDir, "Ini files (*.ini)", 18, "login.ini" ) If $file == "" Then Exit EndIf IniWrite ( $path & "\infostore.ini", "location", "info", $file ) $storepath = IniRead ( $path & "\infostore.ini", "location", "info", "Not found" ) EndSelect #EndRegion --- CodeWizard generated code End --- EndIf Local $readhold = IniReadSectionNames($storepath) $entercomp = False $enterref = False $entered = False $seafile = @ScriptDir & "\1_ClipboardHelpAndSpell.ico" $tune = False If $exist = False Then names(True) EndIf Func names($hodd) $errr = False #Region --- CodeWizard generated code Start --- ;InputBox features: Title=Yes, Prompt=Yes, Default Text=No, Mandatory If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer $sInputBoxAnswer = InputBox("Name", "Please enter your first and last name.", "", " M") Select Case @error = 0 $Namearray = StringSplit($sInputBoxAnswer, " ") If $Namearray[0] = 2 And $Namearray[2] <> "" Then IniWrite($storepath, "Name", "First", encry ($Namearray[1])) IniWrite($storepath, "Name", "Last", encry ($Namearray[2])) #Region --- CodeWizard generated code Start --- ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=None MsgBox(0,"data","Encrypt 1: " & encry ($Namearray[1]) & @CRLF & "Encrypt 2: " & encry ($Namearray[2]) & @CRLF & "Decrypt 1: " & decry ( IniRead ( $storepath, "Name", "First", "na" ) ) & @CRLF & "Decrypt 2: " & decry ( IniRead ( $storepath, "Name", "Last", "na" ) )) #EndRegion --- CodeWizard generated code End --- Else #Region --- CodeWizard generated code Start --- ;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Icon=Critical If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox($MB_YESNO + $MB_ICONHAND, "an error occured", "Did you put input your full name separated by space? Do you want to try again?") Select Case $iMsgBoxAnswer = $IDYES names(True) Case $iMsgBoxAnswer = $IDNO $errr = True EndSelect #EndRegion --- CodeWizard generated code Start --- EndIf Case @error = 1 ;The Cancel button was pushed $errr = True Case @error = 3 ;The InputBox failed to open $errr = True EndSelect #EndRegion --- CodeWizard generated code Start --- If $hodd = False And $errr = False Then #Region --- CodeWizard generated code Start --- ;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Icon=None If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox($MB_YESNO,"Restart","You must close then relaunch this program in order for the additions/changes you have made to display. Would you like to auto-restart the program now?") Select Case $iMsgBoxAnswer = $IDYES Exit 1 Case $iMsgBoxAnswer = $IDNO EndSelect #EndRegion --- CodeWizard generated code End --- EndIf EndFunc ;==>names Func encry ( $input2 ) _Crypt_Startup () $sret = _Crypt_EncryptData ( $input2, $key, $CALG_USERKEY ) _Crypt_Shutdown() Return $sret EndFunc Func decry ( $input ) _Crypt_Startup ( ) $rret = _Crypt_DecryptData ( $input, $key, $CALG_USERKEY ) _Crypt_Shutdown () Return $rret EndFunc Edited March 2, 2016 by MattHiggs Link to comment Share on other sites More sharing options...
MattHiggs Posted March 2, 2016 Author Share Posted March 2, 2016 Nevermind. found answer. Needed to use Binarytostring function my bad. Thanks for the help Link to comment Share on other sites More sharing options...
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