rickybobby Posted April 2, 2014 Posted April 2, 2014 I'm attempting to decrypt a file previously encrypted with the encrypt file function; then read that file into an array and display it. When I read the file into an array it still shows me garbled text if any at all. What am I doing wrong here? $serial = "stepping through array var" $FileHandle = "C:\XXX\Serial.txt" If FileExists($FileHandle) Then $Password = "password" _Crypt_DecryptFile($FileHandle, $FileHandle, $Password, $CALG_RC4) $FileArray = 0 ;initilze computer list array _FileReadToArray($FileHandle, $FileArray) _ArrayDisplay($FileArray) ;why is this showing encrpyted data?!?! FileOpen($FileHandle) FileWriteLine($FileHandle, $serial) FileClose($FileHandle) Else FileOpen($FileHandle) FileWriteLine($FileHandle, $serial) FileClose($FileHandle) EndIf $Password = "password" _Crypt_EncryptFile( $FileHandle, $FileHandle, $Password, $CALG_RC4) Next Any help is greatly appreciated!
Solution jdelaney Posted April 2, 2014 Solution Posted April 2, 2014 Might be because you are decrypting to the same file. Add this, and check the error that occurs: _Crypt_DecryptFile($FileHandle, $FileHandle, $Password, $CALG_RC4) msgbox(1,1,@error) IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
rickybobby Posted April 2, 2014 Author Posted April 2, 2014 @error is 0 for each, i'll try changing the files around.
rickybobby Posted April 2, 2014 Author Posted April 2, 2014 Might be because you are decrypting to the same file. Add this, and check the error that occurs: _Crypt_DecryptFile($FileHandle, $FileHandle, $Password, $CALG_RC4) msgbox(1,1,@error) Yep decrypting to the same file was the problem.
jdelaney Posted April 2, 2014 Posted April 2, 2014 (edited) It works when I change the file vars between encrypt and decrypt #include <Crypt.au3> #include <File.au3> #include <Array.au3> $serial = "stepping through array var" $File = @DesktopDir & "\Serial.txt" $File2 = @DesktopDir & "\Serial2.txt" $Password = "password" Local $FileArray[1];initilze computer list array If Not FileExists($File) Then _FileCreate($File) FileWrite($File,"add something in") ConsoleWrite(FileRead($File) & @CRLF) _Crypt_EncryptFile($File,$File2,$Password,$CALG_RC4) ConsoleWrite(FileRead($File2) & @CRLF) EndIf $iSuccess = _Crypt_DecryptFile($File2,$File,$Password,$CALG_RC4) ConsoleWrite(FileRead($File3) & @CRLF) Edited April 2, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
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