Sign in to follow this  
Followers 0
FMS

data empty afther encrypt/decrypt

5 posts in this topic

Hello,

I think this is a simple question if you know the answer.

At this function i try to  (encrypt -> decrypt -> change -> encrypt ->decrypt->check ) an array.
This is a snippet from a larger script but the error is the same.
I do this encrypt decrypt action so i can save some setting along the way in a file.

But at the end (when i change the data and not when i dont change the data) is empty.

does somebody see what i'm doing wrong here?

 

Func test()


   Local $LC_timestamp = @MDAY & "." & @MON & "." & @YEAR & "_" & @HOUR & ":" & @MIN & ":" & @SEC
   Global $GL_USS_base_count = 4
   Global $GL_USS_base[$GL_USS_base_count][2] = [["nickname", "FMS"], ["last_login", $LC_timestamp], ["login_count", "1" ], ["naam3", $LC_timestamp]]

   Global $encrypted_GL_USS_true[$GL_USS_base_count]
   Global $encrypted_GL_USS_content_true[$GL_USS_base_count]
   Global $GL_array_decrypted_USS_names[$GL_USS_base_count]
   Global $GL_array_decrypted_USS_settings[$GL_USS_base_count]

   MsgBox($MB_SYSTEMMODAL, "should be 1", $GL_USS_base[2][1])

   ;make
   for $i = 0 to $GL_USS_base_count -1
      $encrypted_GL_USS_true[$i] = _Crypt_EncryptData($GL_USS_base[$i][0], $GL_encr_key_settings, $CALG_AES_128)
      $encrypted_GL_USS_content_true[$i] = _Crypt_EncryptData($GL_USS_base[$i][1], $GL_encr_key_settings, $CALG_AES_128)
   Next

   ;get
   for $i = 0 to $GL_USS_base_count -1
      $GL_array_decrypted_USS_names[$i] = binarytostring(_Crypt_DecryptData(binary($encrypted_GL_USS_true[$i]), $GL_encr_key_settings, $CALG_AES_128))
      $GL_array_decrypted_USS_settings[$i] = binarytostring(_Crypt_DecryptData(binary($encrypted_GL_USS_content_true[$i]), $GL_encr_key_settings, $CALG_AES_128))
   Next

   MsgBox($MB_SYSTEMMODAL, "should be 1", $GL_array_decrypted_USS_settings[2])

   ;change
   $GL_array_decrypted_USS_settings[2] = $GL_array_decrypted_USS_settings[2] + "1"
   MsgBox($MB_SYSTEMMODAL, "should be 2", $GL_array_decrypted_USS_settings[2])
   ;save
   for $i = 0 to $GL_USS_base_count -1
      $encrypted_GL_USS_true[$i] = _Crypt_EncryptData($GL_array_decrypted_USS_names[$i], $GL_encr_key_settings, $CALG_AES_128)
      $encrypted_GL_USS_content_true[$i] = _Crypt_EncryptData($GL_array_decrypted_USS_settings[$i], $GL_encr_key_settings, $CALG_AES_128)
   Next
   ;get
   for $i = 0 to $GL_USS_base_count -1
      $GL_array_decrypted_USS_names[$i] = binarytostring(_Crypt_DecryptData(binary($encrypted_GL_USS_true[$i]), $GL_encr_key_settings, $CALG_AES_128))
      $GL_array_decrypted_USS_settings[$i] = binarytostring(_Crypt_DecryptData(binary($encrypted_GL_USS_content_true[$i]), $GL_encr_key_settings, $CALG_AES_128))
   Next

   ;check
   MsgBox($MB_SYSTEMMODAL, "should be 2", $GL_array_decrypted_USS_settings[2]) ;why is this emty?????
EndFunc

thanks in advanced


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites



Why are you converting the binary string returned by _Crypt_EncryptData to binary value when you try to decrypt it.  It is already a binary string, there is not need to use the Binary function.

This 

BinaryToString(_Crypt_DecryptData(Binary($encrypted_GL_USS_true[$i]), $GL_encr_key_settings, $CALG_AES_128))

should be

BinaryToString(_Crypt_DecryptData($encrypted_GL_USS_true[$i], $GL_encr_key_settings, $CALG_AES_128))

 

Adam

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Ke thans for the input @AdamUL, i idd tried it and it's still nothing at the and.

Edited by FMS

as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

Now I've looked it over and it seems when you add +1 to the decrypted data, you convert to int instead of string and convert the binary return for a int with the value of 2, to a string.

So basically change:

$GL_array_decrypted_USS_settings[2] = $GL_array_decrypted_USS_settings[2] + "1"

To:

$GL_array_decrypted_USS_settings[2] = String( $GL_array_decrypted_USS_settings[2] + "1" )

 

Share this post


Link to post
Share on other sites

Yes , that totaly was it :) thanks


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • FMS
      By FMS
      Hello,

      I'm having trouble whit a scipt what I'm building where this is a snippit from, and hope somebody can help me whit.
      The problem lies in when i push the "add" button i want to check if the "user" already exists.
      But the search code i build founds 2 hits when i know there is only 1 hit.
      does somebody knows what I'm doing wrong?
      thanks in advance.

      Ps. if somebody knows " if i found the right user how can i rewrite the password for him/her? " an answer to that will be most appriciated
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <AutoItConstants.au3> #include <Array.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <File.au3> #Include <Timers.au3> #include <Crypt.au3> #include <GuiEdit.au3> $Form1 = GUICreate("Pie", 170, 235, 190, 200) local $usernames[0] local $passwords[0] global $selectuser = GUICtrlCreateCombo("", 21, 95, 130, 20) $addusername = GUICtrlCreateButton("Add", 21, 170, 130, 30) $usernamefield = GUICtrlCreateInput("", 21, 120, 130, 20) $passwordfield = GUICtrlCreateInput("", 21, 145, 130, 20, 0x0020) func encrypt() Local $hFileOpen = FileOpen("data.srmt", $FO_APPEND) if guictrlread($usernamefield) <> "" then ;~ local $encryptedusername = string(guictrlread($usernamefield)) ;~ local $encryptedpassword = string(guictrlread($passwordfield)) local $encryptedusername = string(_Crypt_EncryptData(guictrlread($usernamefield), "P14h735536jk3fvvbg", $CALG_AES_128)) local $encryptedpassword = string(_Crypt_EncryptData(guictrlread($passwordfield ), "P14h735536jk3fvvbg", $CALG_AES_128)) Local $iCheck_hit = False ConsoleWrite (@CRLF & "##############################################"& @CRLF) if ubound($usernames)> 0 then for $i = 0 to ubound($usernames)-1 If guictrlread($usernamefield) = $usernames[$i] Then $iCheck_hit = True ConsoleWrite ( "Found! "& @CRLF & $usernames[$i] & " = " & guictrlread($usernamefield) & @CRLF & "i = " & $i & @CRLF & @CRLF) ;~ Else ;~ ConsoleWrite ( "No! "& @CRLF & $usernames[$i] & " = " & guictrlread($usernamefield) & @CRLF & "i = " & $i & @CRLF & @CRLF) EndIf next EndIf ConsoleWrite ( "##############################################"& @CRLF) If $iCheck_hit = False Then FileWrite($hFileOpen, $encryptedusername & @CRLF) FileWrite($hFileOpen, $encryptedpassword & @CRLF) EndIf EndIf FileClose($hFileOpen) EndFunc func decrypt() Local $hFileOpen = FileOpen("data.srmt", $FO_READ) ;~ consolewrite(_FileCountLines("data.srmt") & " lines in the file" & @CRLF) for $i = 1 to _FileCountLines("data.srmt")/2 local $encryptedusername = FileReadLine($hFileOpen) local $encryptedpassword = FileReadLine($hFileOpen) ;~ consolewrite($encryptedusername & @CRLF) ;~ consolewrite($encryptedpassword & @CRLF) ;~ _ArrayAdd($usernames, FileReadLine($hFileOpen)) ;~ _ArrayAdd($passwords, FileReadLine($hFileOpen)) _ArrayAdd($usernames, binarytostring(_Crypt_DecryptData(binary($encryptedusername), "P14h735536jk3fvvbg", $CALG_AES_128))) _ArrayAdd($passwords, binarytostring(_Crypt_DecryptData(binary($encryptedpassword), "P14h735536jk3fvvbg", $CALG_AES_128))) Next FileClose($hFileOpen) ;~ consolewrite(ubound($usernames) & " entries in array") ;~ _arraydisplay($usernames) if ubound($userNames)> 0 then for $i = 0 to ubound($usernames)-1 GUICtrlSetData($selectuser, $usernames[$i]) next EndIf endfunc func updatecomboandinfo() if not GUICtrlRead($usernamefield) = "" Then _ArrayAdd($usernames, GUICtrlRead($usernamefield)) _ArrayAdd($passwords, GUICtrlRead($passwordfield)) GUICtrlSetData($selectuser, $usernames[UBound($usernames)-1]) EndIf EndFunc decrypt() GUISetState(@SW_SHOW) While True $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $addusername updatecomboandinfo() encrypt() GUICtrlSetData($usernamefield, "") GUICtrlSetData($passwordfield, "") Case $selectuser if ubound($usernames)> 0 then for $i = 0 to ubound($usernames)-1 ;~ msg( "error",$array_decrypted_usernames[$i]) If $usernames[$i] = GUICtrlRead($selectuser) Then GUICtrlSetData($usernamefield, $usernames[$i]) GUICtrlSetData($passwordfield, $passwords[$i]) consolewrite("YES " & $i & " = " & $usernames[$i] & " | ctr = " & GUICtrlRead($selectuser) & @CRLF) Else ;~ msg( "error",$array_decrypted_usernames[$i]) consolewrite("NO " & $i & " = " & $usernames[$i] & " | ctr = " & GUICtrlRead($selectuser) & @CRLF) EndIf next EndIf EndSwitch WEnd  
    • 31290
      By 31290
      Hi everyone, 
      I'm building some script that will encrypt some user password and store it in an ini file.
      I'd like to recall the password in a putty session but I can't figure out how to decrypt it:

      So far, I have:
      Global $Images = "C:\SAC_IS\ATL_Laptop\Resources\Images\" Global $WorkingDir = "C:\SAC_IS\Switches_Toolbox\" Global $Settings = $WorkingDir & "\Settings.ini" DirCreate ($WorkingDir) _FirstRun() While 1 Sleep(10) WEnd Func _FirstRun() If FileExists ("C:\SAC_IS\Switches_Toolbox\Settings.ini") Then _LoginfoGUI() Else MsgBox (64, "PUTTY EXECUTABLE", "First, select PUTTY.EXE path") Global $PuttyPath = FileOpenDialog("Please indicate putty.exe path", @HomeDrive, "exe (*.exe)") _LoginfoGUI() If @Error Then Global $Error = MsgBox(21, "Error!", "Can't find PUTTY.EXE!"& @CRLF & "Click Retry or Cancel to Quit") If $Error = $IDRETRY Then _FirstRun() Else _Exit() EndIf Else FileInstall ("C:\Users\h74033\Desktop\Scirpts\Switches\Settings.ini", $WorkingDir & "\Settings.ini", 1) IniWrite ($Settings, "Putty", "Path", $PuttyPath) EndIf EndIf ; SwitchesToolboxGui() Endfunc Func _Exit() Exit EndFunc Func _LoginfoGUI() Global $LoginfoGUI = GUICreate("Switches Toolbox Configuration", 300, 300, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit", $LoginfoGUI) GUICtrlCreatePic ($Images & "\SAClogo.jpg", 30, 10, 240, 80) GUISetBkColor ($Color_White) GUICtrlCreateLabel("-- SWITCHES TOOLBOX --", 85, 100, 150, 25) GUICtrlSetFont (-1, 8.5, 700, 0) GUICtrlCreateLabel("Please provide required information:", 10, 130, 250, 25) GUICtrlCreateLabel("-Global ID:", 10, 170, 60, 30) GUICtrlSetFont (-1, 8.5, 700, 0) GUICtrlCreateLabel("-Password:", 10, 210, 70, 30) GUICtrlSetFont (-1, 8.5, 700, 0) Global $GIDInput = GUICtrlCreateInput("", 90, 168, 80, 20) Global $PassInput = GUICtrlCreateInput("", 90, 205, 150, 20, $ES_PASSWORD) GUICtrlCreateButton ("Submit", 100, 245, 100, 25) GUICtrlSetOnEvent(-1, "_Submit") GUISetState(@SW_SHOW) EndFunc Func _Submit() Global $GID = GuiCtrlRead($GIDInput) Global $EncryptedPwd = _Crypt_HashData (GuiCtrlRead($PassInput), $CALG_MD2) IniWrite ($Settings, "Username", "Gid", $Gid) IniWrite ($Settings, "Encryption", "Password", $EncryptedPwd) ;MsgBox(0, "re", $EncryptedPwd) EndFunc How can I achieve that please?
      Thanks in advance
       
    • MikahS
      By MikahS
      Short-Order Encrypter
      Just a fun project I had making a Crypt GUI that will encrypt and decrypt messages and files. All regular encryption types have been included for use. It will dynamically ask for a password, making it so there are never any passwords stored inside script. All dynamically built. I have included source code for your pleasure
       
       
       
      I wanted to get this onto the forum just see if anyone had any use for it. I am open and listening for questions, concerns, and comments
       
      Short-Order Encrypter.zip
      Short-Order EncrypterV1.0.5.zip
      Short-Order EncrypterV1.5.0.zip
      Short-Order Encrypter V1.6.0.zip
      Short-Order Encrypter V1.6.1.zip
       
      Current Version: 1.6.1.0
       
       
      Version History: