2Radon Posted April 24, 2014 Share Posted April 24, 2014 (edited) I can't come to why it only writes ONE section in the ini file EVER. Sorry I can't put up the whole program, but it is quite extensive and may have sensitive information also. Hope you can help anyhow. expandcollapse popup#include <Crypt.au3> #include <MsgBoxConstants.au3> #include <ColorConstants.au3> $rUSR = GUICtrlRead($txtUSR) ; Read entered USR and PW $rPW = GUICtrlRead($txtPW) If Not($rUSR="") And Not($rPW="") Then ; If not empty _Crypt_Startup() $rUSR = _StringEncrypt(1, $rUSR, "cryptpw") ; 2 ARPL $rPW = _StringEncrypt(1, $rPW, "cryptpw") ; Encrypt the string If FileExists("Creds") Then ; If a file containing credentials doesn't already exist _Crypt_DecryptFile("Creds", "Creds.ini", "cryptpw2, $CALG_AES_256) ; Turn it back into an ini file FileSetAttrib("Creds.ini", "+H") EndIf IniWrite("Creds.ini", $rCredsButton, "USR", $rUSR) ; Add the encrypted USR and PW values under the chosen section IniWrite("Creds.ini", $rCredsButton, "PW", $rPW) _Crypt_EncryptFile("Creds.ini", "Creds", "cryptpw2, $CALG_AES_256) ; Turn the ini back into an encrypted file _Crypt_Shutdown() FileSetAttrib("Creds", "+H") FileDelete("Creds.ini") ; Delete the ini so that only a double-encrypted credentials file remains IniWrite($fINI, "Creds", $rCredsButton, 1) GUICtrlSetData($txtUSR, "") GUICtrlSetData($txtPW, "") Else MsgBox($MB_OK, "Wrong Input", "Please enter Username and Password for " & $rCredsButton & "!") ; USR and PW not entered EndIf Func _StringEncrypt($fEncrypt, $sData, $sPassword) _Crypt_Startup() ; Start the Crypt library. Local $sReturn = '' If $fEncrypt Then ; If the flag is set to True then encrypt, otherwise decrypt. $sReturn = _Crypt_EncryptData($sData, $sPassword, $CALG_AES_256) Else $sReturn = BinaryToString(_Crypt_DecryptData($sData, $sPassword, $CALG_AES_256)) EndIf _Crypt_Shutdown() ; Shutdown the Crypt library. Return $sReturn EndFunc ;==>_StringEncrypt Edited April 24, 2014 by 2Radon Link to comment Share on other sites More sharing options...
JohnOne Posted April 24, 2014 Share Posted April 24, 2014 Why should it write to any section other than "Creds"? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
2Radon Posted April 24, 2014 Author Share Posted April 24, 2014 Why should it write to any section other than "Creds"? As written in IniWrite in that code above, it must write in Creds.ini in section $rCredsButon (which can be, for example, "Google", "Bank", "Facebook"...) in the keys USR and PW under that section. So if there is already a section [Google] with USR and PW under it, next time it writes in case of [bank] it should create a new section but with keys USR and PW also under it. All I'm getting is one section in Creds.ini getting overwritten every time with the new values in section and keys. Link to comment Share on other sites More sharing options...
2Radon Posted April 24, 2014 Author Share Posted April 24, 2014 Seems I have found out through testing that when decrypting it somehow brings back only one Section of the ini file. What am I fusing here?! Link to comment Share on other sites More sharing options...
JohnOne Posted April 24, 2014 Share Posted April 24, 2014 (edited) I think you have filename and section confused. EDIT: Or maybe section and key Edited April 24, 2014 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
2Radon Posted April 24, 2014 Author Share Posted April 24, 2014 I think you have filename and section confused. EDIT: Or maybe section and key Nay, as stated in the help file for IniWrite(), first comes file, then section, then key, then value. Just like I have. Link to comment Share on other sites More sharing options...
JohnOne Posted April 24, 2014 Share Posted April 24, 2014 Yes, and in your code the only section you attempt to write to is "Creds". IniWrite($fINI, "Creds", $rCredsButton, 1) That's why it ... only writes ONE section in the ini file EVER AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
2Radon Posted April 24, 2014 Author Share Posted April 24, 2014 (edited) Yes, and in your code the only section you attempt to write to is "Creds". IniWrite($fINI, "Creds", $rCredsButton, 1) Sorry, should have cropped that too. That is a different ini file. This is the most important part: _Crypt_Startup() $rUSR = _StringEncrypt(1, $rUSR, "cryptpw") ; 2 ARPL $rPW = _StringEncrypt(1, $rPW, "cryptpw") ; Encrypt the string If FileExists("Creds") Then ; If a file containing credentials doesn't already exist _Crypt_DecryptFile("Creds", "Creds.ini", "cryptpw2, $CALG_AES_256) ; Turn it back into an ini file FileSetAttrib("Creds.ini", "+H") EndIf IniWrite("Creds.ini", $rCredsButton, "USR", $rUSR) ; Add the encrypted USR and PW values under the chosen section IniWrite("Creds.ini", $rCredsButton, "PW", $rPW) _Crypt_EncryptFile("Creds.ini", "Creds", "cryptpw2, $CALG_AES_256) ; Turn the ini back into an encrypted file _Crypt_Shutdown() It currently saves 2 out of 4 different sections for some friggin flippin dog knows what reason and drives me mad and keeps me tied. Edited April 24, 2014 by 2Radon Link to comment Share on other sites More sharing options...
BrewManNH Posted April 24, 2014 Share Posted April 24, 2014 Is that your actual code, because you have a missing quote in the line below? It belongs after cryptw2. _Crypt_DecryptFile("Creds", "Creds.ini", "cryptpw2, $CALG_AES_256) If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
2Radon Posted April 25, 2014 Author Share Posted April 25, 2014 Is that your actual code, because you have a missing quote in the line below? It belongs after cryptw2. _Crypt_DecryptFile("Creds", "Creds.ini", "cryptpw2, $CALG_AES_256) Nop, I simply replaced sensitive information as I was writing this post. In my real code it has everything and works but as I described weirdly behaves I believe... Link to comment Share on other sites More sharing options...
JohnOne Posted April 25, 2014 Share Posted April 25, 2014 Your best bet here, is to post a runnable example of your problem, frankly I have no Idea what it is you're doing. When you do this, it usually turns out you solve your issue along the way. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Guest Posted April 25, 2014 Share Posted April 25, 2014 (edited) Instead of writing the data to disk without encryption and then encrypt the data on the disk, for security reasons it is better for you to write the encrypted data directly to disk using >IniVirtual What you can do is: 1) read the encrypted data (ini data) from the disk in to a variable 2) decrypt the variable 3) do what you want to do with IniVirtual - so after i did what you want, the decrypted variable (the ini data) was updated. 4) Encrypt again the updated decrypted variable so you will have encrypted variable 5) Write the encrypted variable to the file Edited April 25, 2014 by Guest Link to comment Share on other sites More sharing options...
2Radon Posted April 25, 2014 Author Share Posted April 25, 2014 (edited) I want to give the program for you guys to see and find the problem, but it's got sensitive information for a company, some names, which could be really messy to cover. I am still constantly testing it all day and it is just senseless. The code I wrote in the first post is, I think, responsible for writing only ONE section + USR and PW key in the file that is double encrypted. Could double encryption mess it hard? It encrypts the ini value, which is written in the ini, and this ini file is encrypted. To retrieve the PW and USR it is done vice versa. But It won't write more than one section, no matter that it is different. Also, a bit earlier it worked by saving 2 sections and not saving 2 others. Now it's back at one. No idea. I read the code through several times, it is supposed to do what I want, everything matches from A to Z, but it doesn't. I don't see it. Can I maybe log whatever the program does very closely and see where it writes in the file and what happens then, and what happens in encryption steps? Shouldn't this successfully Decrypt the file, delete the said lines and then encrypt this modified file back to the previous file? If FileExists($fCreds) Then _Crypt_Startup() _Crypt_DecryptFile($fCreds, $fCredsINI, "AteaReady4PonyLimbo", $CALG_AES_256) ; Turn it back into an ini file FileSetAttrib($fCredsINI, "+H") IniDelete("Creds.ini", $rCredsButton);, "USR") IniDelete("Creds.ini", $rCredsButton);, "PW") ;IniWrite($fCredsINI, $rCredsButton, "USR", "0") ; Doesn't work as well ;IniWrite($fCredsINI, $rCredsButton, "PW", "0") _Crypt_EncryptFile($fCredsINI, $fCreds, "AteaReady4PonyLimbo", $CALG_AES_256) ; Turn the ini back into an encrypted file _Crypt_Shutdown() FileSetAttrib($fCreds, "+H") FileDelete($fCredsINI) ; Delete the ini so that only a double-encrypted credentials file remains Edited April 25, 2014 by 2Radon Link to comment Share on other sites More sharing options...
JohnOne Posted April 25, 2014 Share Posted April 25, 2014 Create a runnable code that just deals with the encryption, and demonstrates your issue, use whatever names and passwords you want. make them up. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
2Radon Posted April 25, 2014 Author Share Posted April 25, 2014 Attached a new code I made. This one works better though, but still, when I mess around with deleting and writing and other things I can do with this it ends up in about the same glitch. Play around with this and see that it doesn't work as intended: Creds and Creds.ini are hidden files. Use WriteCreds.au3 to write to Creds.ini and then encrypt to Creds. Use ReadCredsTest.au3 to see what it can read out of Creds (not Creds.ini). Using WriteCreds GUI, delete some, write some again, overwrite some, check inside Creds.ini and what ReadCredsTest.au3 says. Gosh! CredsSolving.zip CredsSolving.zip Link to comment Share on other sites More sharing options...
FireFox Posted April 25, 2014 Share Posted April 25, 2014 FYI, there's an >UDF to encrypt an ini. Link to comment Share on other sites More sharing options...
2Radon Posted April 25, 2014 Author Share Posted April 25, 2014 (edited) FYI, there's an >UDF to encrypt an ini. Dangit, things I didn't really expect appear in UDFs! But regarding my own pile of code - why does it do so? Can I make it work without digging into this UDF? Does double-encryption like I am doing help any actually? I want to hide the fact that it is an ini file also, like I am doing. Edited April 25, 2014 by 2Radon Link to comment Share on other sites More sharing options...
FireFox Posted April 25, 2014 Share Posted April 25, 2014 (edited) Sure, but this UDF looks neat (except some mistakes I corrected post #2). Edited April 25, 2014 by FireFox Link to comment Share on other sites More sharing options...
2Radon Posted April 25, 2014 Author Share Posted April 25, 2014 (edited) Sure, but this UDF looks neat (except some mistakes I corrected post #2). So can you come up with why exactly my code makes flawed results like it does? Is it AutoIT related, not really a fault in my code per se? Edited April 25, 2014 by 2Radon Link to comment Share on other sites More sharing options...
FireFox Posted April 25, 2014 Share Posted April 25, 2014 I haven't looked your code. Your fault I presume. 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