Sign in to follow this  
Followers 0
Warmonger

[Support] Encryption Check Function

10 posts in this topic

#1 ·  Posted (edited)

Basically what im trying to do. Is pull a string from a ini file. And check if its encrypted. If it is not encrypted then encrypted it, if it is then skip the encryption routine. How would I go about doing that, because _StringEncrypt just keeps encrypting the string over and over again. Thanks.

Edited by Warmonger

Share this post


Link to post
Share on other sites



Try writing another key to the ini file when you encrypt the string to act as a flag like isEncrypted=1

Share this post


Link to post
Share on other sites

Try writing another key to the ini file when you encrypt the string to act as a flag like isEncrypted=1

I have done that before. But I am now trying to make it automatic.

Share this post


Link to post
Share on other sites

How would the program know if the line has been encrypted or is just a random collection of characters?


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 Gude
How 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

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I wrote a script the other day and had the same problem.

this is what I did:

Modify the encrypting function to add "*" at the end of the encrypted string.

have your decrypting function look for the little star => "*" <=

If the star was detected make the string pass through a process that removes the little star and decrypt the string.

Hur dur

just in case you need more info..

Use "stringlen" to find the amount of characters in the string, then use stringright minus 1 @ the number of char returned by stringlen.

check if its the star

Edit: cant find the original script but this should be a good example...

#include<Crypt.au3>

Global $Exclusions = "Svchost.exe,explorer.exe"; Exclude file names
Global $ExclusionsByExt = "ini" ; Exclude file extensions


_Crypt_Startup()
If not FileExists(@DesktopDir & "\Hash.ini") Then
    _ScanNetwork();Create hash log
Else
    _ScanNetwork(True)
EndIf
_Crypt_Shutdown()

Func _ScanNetwork($State = False)

    If  $State = False  Then
        _Scan(@HomeDrive)
    ElseIf $State = True Then
        _Anulyze(IniReadSection(@DesktopDir & "\Hash.ini", "EXE Values"))
        _Anulyze(IniReadSection(@DesktopDir & "\Hash.ini", "DLL Values"))
        _Anulyze(IniReadSection(@DesktopDir & "\Hash.ini", "BAT Values"))
        _Anulyze(IniReadSection(@DesktopDir & "\Hash.ini", "SCR Values"))
        _Anulyze(IniReadSection(@DesktopDir & "\Hash.ini", "MSI Values"))
    Else
        MsgBox(16,"","Error")
    EndIf

EndFunc

Func _Scan($SourceFolder)

    Local $File
    Local $Search

    $Search = FileFindFirstFile($SourceFolder & "\*.*")
    If $Search = -1 Then Return

    While 1
        $File = FileFindNextFile($Search)
        If @error = 1 Then ExitLoop
        If @extended = 1 Then
             _Scan($SourceFolder & "\" & $File)
         Else
            _Xzamin($SourceFolder & "\" & $File)
        EndIf
    WEnd

    FileClose($Search)

EndFunc   ;==>_SCANSYSTEM

Func _Xzamin($File)

    Local $S=StringSplit($File,"\",2)
    Local $i=UBound($S) - 1
    Local $S2=StringSplit($S[$i],".",2)
    Local $I2=UBound($S2) - 1

    If StringInStr($Exclusions,$S[$i]) Then Return 1; exclusions ~
    If Not StringInStr($ExclusionsByExt,$S2[$I2]) Then Return 1; exclusions ~
    If Round(FileGetSize($File)/1048576,2) > 2 Then Return 1;exclude files bigger than 2mb...

    Local $FO=FileOpen($File)
    If @error Then Return @error

    Local $FR=FileRead($FO)
    IniWrite(@DesktopDir & "\Hash.ini",$S2[$I2]&" Values",$File,_Crypt_HashData($FR,$CALG_MD5)&"*"&FileGetTime($File,0,1))
    FileClose($FO)

    Return 1

EndFunc

Func _Anulyze($Var)

    If not IsArray($Var) Then Return

    $i = 0
    Do
        $i += 1
        ToolTip("PROCESSING: "&$var[$i][0])
        Local $FZ=FileGetTime($var[$i][0],0,1)
        Local $S1=StringSplit($var[$i][1],"*",2)
        Local $I1=UBound($S1) - 1
        Local $IH=StringSplit($var[$i][1],"*",2)
        Local $FH=UBound($S1) - 2

        ;If $FZ <> $S1[$I1] Then
        ;   If Not $FZ = 0 Then
        ;       MsgBox(0,$var[$i][0],"Before:"&$S1[$I1]&@CRLF&"AFTER:"&FileGetTime($var[$i][0],0,1))
        ;    EndIf
        ;EndIf
        Local $FO=FileOpen($var[$i][0])
        Local $FR=FileRead($FO)
        If _Crypt_HashData($FR,$CALG_MD5) <> $IH[$FH] Then
            MsgBox(0,_Crypt_HashData($FR,$CALG_MD5),$IH[$FH])
        EndIf
        FileClose($FO)
    Until $i = $var[0][0]

    MsgBox(0,"","Exiting")
    Return 1
EndFunc

A problem I stumbled onto was that iniread only returns a limited amount of data so the file change scanner doesn't scan every file.

It can easily be adjusted to store all data into an array and store it in binary into a file.

Edited by System238

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

How would the program know if the line has been encrypted or is just a random collection of characters?

Given the return of some functions, it maybe possible to do. Im play around with it a bit, if i come up with something ill post.

I wrote a script the other day and had the same problem.

this is what I did:

Modify the encrypting function to add "*" at the end of the encrypted string.

have your decrypting function look for the little star => "*" <=

Hur dur

Good idea, im not good at brainstorming little bypass's like this. Ill give it a shot and let you know how it turns out.

Edited by Warmonger

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Thanks for the idea System238. I have solved this.

Result:

#include <String.au3>

$aPass = IniRead('1.ini', '1', 'PASS', 0)

$HashCheck = StringInStr($aPass, '*')

If $HashCheck = 0 Then
    $ePass = _StringEncrypt(1, $aPass, 'test')
    IniWrite('1.ini', '1', 'PASS', ' ' & $ePass & '*')
    MsgBox(0, 'Error', 'String Is Not Encrypted')
Else
    $tPass = StringTrimRight($aPass, 1)
    $dPass = _StringEncrypt(0, $tPass, 'test')
    MsgBox(0, 'Pass', 'Your Password Is ' & $dPass)
EndIf
Edited by Warmonger

Share this post


Link to post
Share on other sites

Thanks for the idea System238. I have solved this.

Result:

#include <String.au3>

$aPass = IniRead('1.ini', '1', 'PASS', 0)

$HashCheck = StringInStr($aPass, '*')

If $HashCheck = 0 Then
    $ePass = _StringEncrypt(1, $aPass, 'test')
    IniWrite('1.ini', '1', 'PASS', ' ' & $ePass & '*')
    MsgBox(0, 'Error', 'String Is Not Encrypted')
Else
    $tPass = StringTrimRight($aPass, 1)
    $dPass = _StringEncrypt(0, $tPass, 'test')
    MsgBox(0, 'Pass', 'Your Password Is ' & $dPass)
EndIf

Although it may be better to look for a sequence of characters rather then just that little star, but you get the idea.

Glad I could be of assistance.


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

Although it may be better to look for a sequence of characters rather then just that little star, but you get the idea.

Glad I could be of assistance.

Well RC4 only encrypts to characters and numbers. So unless they use a * in their original passwords then it should be fine. These passwords must be easily remembered by the end user (a-z0-9) so I doubt special characters will become a problem. But thanks for the concern. I may make the check a little better later on but works for now. :unsure:

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Well RC4 only encrypts to characters and numbers. So unless they use a * in their original passwords then it should be fine. These passwords must be easily remembered by the end user (a-z0-9) so I doubt special characters will become a problem. But thanks for the concern. I may make the check a little better later on but works for now. :unsure:

Oh, my bad, I didn't realize that when I was replying..

Any way, I remembered you said something about storing data to an ini file, and as I said before in the above post, ini's are

limited and I was gonna look for a workaround, and boy was I surprised when I found out there was a SQlite UDF included into the Autoit install.

This is perfect for storing an unworldly amount of data.

#include<SQLite.au3>
#include<SQLite.dll.au3>
    Local $aResult, $iRows, $iColumns, $iRval, $hQuery, $aRow, $sMsg
$Table = "DataBase"
_SQLite_Startup()
If NOT FileExists("Memory.db") Then
    $DB=_SQLite_Open("Memory.db")
    _SQLite_Exec($DB,"CREATE TABLE DataBase (Adress,Val1,Val2,Val3,Val4,Val5);")
    _SQLite_Exec($DB,"CREATE TABLE ScriptData (Adress,Val1,Val2,Val3,Val4,Val5);");not used~
    _DataAddEx($Table,"TABLE 0","Data")
    _DataAddEx($Table,"TABLE 1","Binary Data")
    _DataAddEx($Table,"TABLE 2","More Binary 0101")
    _DataAddEx($Table,"TABLE 3","Extra Binary stuff")
    _DataAddEx($Table,"TABLE 4","Even more binary data for u!")
Else
    $DB=_SQLite_Open("Memory.db")
EndIf

_SQlite_Query (-1, "SELECT * FROM DataBase;", $hQuery) ; the query

While _SQLite_FetchData ($hQuery, $aRow) = $SQLITE_OK
    $sMsg &= $aRow[0]&"*"
WEnd

$ST=StringSplit($sMsg,"*")

For $I = 1 To $ST[0] - 1
    $D=_DataQueryEx("DataBase",$ST[$I])
MsgBox(0,$ST[$I] ,$D)
Next

Func _DataAddEx($Table,$Adress,$Val1,$Val2 = "",$Val3 = "", $Val4 = "",$Val5 = "")
    Local $Data
    _SQLite_QuerySingleRow($DB,"SELECT Adress FROM "&$Table&" WHERE Adress='"&$Adress&"'",$Data)
    If $Data[0] <> "" Then
        _SQLite_Exec($DB,"UPDATE "&$Table&" SET Val1='"&$Val1&"', Val2='"&$Val2&"', Val3='"&$Val3&"', Val4='"&$Val4&"', Val5='"&$Val5&"' WHERE Adress='"&$Adress&"'")
    Else
        _SQLite_Exec($DB,"INSERT INTO "&$Table&" (Adress,Val1,Val2,Val3,Val4,Val5) VALUES ('"&$Adress&"','"&$Val1&"','"&$Val2&"','"&$Val3&"','"&$Val4&"','"&$Val5&"');")
    EndIf
EndFunc

Func _DataQueryEx($Table,$Adress)
    Local $Ret
    If _SQLite_QuerySingleRow($DB,"SELECT * FROM "&$Table&" WHERE Adress='"&$Adress&"'",$Ret) == $SQLITE_OK Then ; =>"*"<= means all...
        If $Ret[0] == "" Then
            Return @error
        Else
            Return $Ret[1]; Remove "[1]" so that you get an array returned, more info.
        EndIf
    EndIf
EndFunc

Func _DataDel($Table,$Adress)
    Local $Ret
    _SQLite_QuerySingleRow($DB,"SELECT Adress FROM "&$Table&" WHERE Adress='"&$Adress&"'",$Ret)
    If $Ret[0] <> "" Then
        _SQLite_Exec($DB,"DELETE FROM "&$Table&" WHERE Adress='"&$Adress&"'")
    EndIf
EndFunc
Edited by System238

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

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