Jump to content

File decryption then fileread to array showing encrypted data


Go to solution Solved by jdelaney,

Recommended Posts

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! :) 

Link to comment
Share on other sites

  • Solution

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.
Link to comment
Share on other sites

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 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.
Link to comment
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
 Share

×
×
  • Create New...