Sign in to follow this  
Followers 0
SmOke_N

Ini Crypt

4 posts in this topic

#1 ·  Posted (edited)

After reading this topic:

I had remembered before I started primarily using data bases for most of my work, I used to have a "Ini/Crypt" au3 I used with a custom encryption.dll I made.

So I decided to sit down and try to re-create it using Crypt.au3 method.

This is a simple version, it doesn't track your pass hashes, it doesn't do verification if the file is encrypted, it just assumes the file is encrypted with the methods you provided in the "_IniCrypt_SetPassword()" function.

It's based on the standard ini functions, so other than:

_IniCrypt_Initiate()

_IniCrypt_SetPassword()

_IniCrypt_Shutdown()

You'd use it the same way.

( Remember, it assumes that the entire ini file is encrypted, so don't assume it will pick up any non-encrypted sections/keys, for that you'll need to use standard functions )

Here's a simple example, some stolen from the help file.

#include <array.au3>
_IniCrypt_Initiate() ; Would be put at the top of a script or when you need to reset after _IniCrypt_Shutdown()
_IniCrypt_SetPassword("mypassword") ; Should be set after initialization 
Global $ga_data[3][2] = [ [ "FirstKey", "FirstValue" ], [ "SecondKey", "SecondValue" ], [ "ThirdKey", "ThirdValue" ] ]
_IniCrypt_WriteSection("mycrypttest.ini", "Section1", $ga_data, 0)
Global $ga_args = _IniCrypt_ReadSection("mycrypttest.ini", "Section1")
_ArrayDisplay($ga_args)
_IniCrypt_Shutdown() ; Used when you need to stop using or when you want to reset password/hash

If you make changes, all I ask is to please make a notation in the "Update Status" at the top of the script of what you changed/added.

Edit:

2011-05-01 - SmOke_N

Fixed: Noticed issue with blank values right after I posted - notation in file

IniCrypt.au3

Edited by SmOke_N
1 person likes this

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites



Very nice, I have been looking for a simple way to store data (.ini files), and a simple way to securely(well, relatively secure depending on the integrity of the key) store data, and I believe I have found it.

Nice Work!


ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Nice UDF.

Seems like no one really tested it, the function _IniCrypt_Delete does not work, here is the fixed code :

;line 109 you forgot the $s_key variable, huh.

$s_key = Hex(_Crypt_EncryptData($s_key, $gh_IniCrypt_Key, $CALG_USERKEY))

Edit : maybe here too :

;line 286

$a_csections[$i] = BinaryToString(_Crypt_DecryptData("0x" & _
$a_csections[$i], $gh_IniCrypt_Key, $CALG_USERKEY))

;line 332
$s_newsection = Hex(_Crypt_EncryptData($s_newsection, $gh_IniCrypt_Key, $CALG_USERKEY))

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

On miércoles, 29 de agosto de 2012 at 8:54 AM, FireFox said:

Edit : maybe here too :

Sorry for posting on an old thread, but found this interesting for learning,

Just to share some corrections in the functions and an example.

;line 109: same correction as FireFox (See the line code in his previous post)
;line 112
Return (String($s_ckey) <> "") ? (IniDelete($s_filename, $s_csection, $s_key)) : ( IniDelete ($s_filename, $s_csection))
;line 286 (see the bigining of the line $a_sections[$i] instead of $a_csections[$i])
$a_sections[$i] = BinaryToString(_Crypt_DecryptData("0x" & _
$a_csections[$i], $gh_IniCrypt_Key, $CALG_USERKEY))
;line 332 (see again the variable at the beginin)
$s_cnewsection = Hex(_Crypt_EncryptData($s_newsection, $gh_IniCrypt_Key, $CALG_USERKEY))
;line 335 (see $s_csection instead of $s_section)
Local $n_ret = IniRenameSection($s_filename, $s_csection, $s_cnewsection, $i_flag)

Example (extended from the SmOke_N example in the first post):

#include <array.au3>
#include "IniCrypt.au3"

_IniCrypt_Initiate() ; Would be put at the top of a script or when you need to reset after _IniCrypt_Shutdown()
_IniCrypt_SetPassword("mypassword") ; Should be set after initialization
Global $ga_data[3][2] = [ [ "FirstKey", "FirstValue" ], [ "SecondKey", "SecondValue" ], [ "ThirdKey", "ThirdValue" ] ]
_IniCrypt_WriteSection("mycrypttest.ini", "Section1", $ga_data, 0)
Global $ga_args = _IniCrypt_ReadSection("mycrypttest.ini", "Section1")
_ArrayDisplay($ga_args, "Section1")

;Changing name of Section1
_IniCrypt_RenameSection("mycrypttest.ini", "Section1" , "Renamed_Section1")
$ga_args = _IniCrypt_ReadSection("mycrypttest.ini", "Renamed_Section1")
_ArrayDisplay($ga_args, "Renamed_Section1")
$ga_args = _IniCrypt_ReadSectionNames("mycrypttest.ini")
_ArrayDisplay($ga_args, "Names")

;Restore the name to Section1 to avoid duplicating sections when running again
_IniCrypt_RenameSection("mycrypttest.ini", "Renamed_Section1" , "Section1")
$ga_args = _IniCrypt_ReadSectionNames("mycrypttest.ini")
_ArrayDisplay($ga_args, "Restored Name")

;Deleting key 1 of Section1
_IniCrypt_Delete("mycrypttest.ini", "Section1", "FirstKey")
Global $ga_args = _IniCrypt_ReadSection("mycrypttest.ini", "Section1")
_ArrayDisplay($ga_args, "Deleted FirstKey")

;Deleting Section1
_IniCrypt_Delete("mycrypttest.ini", "section1")
_IniCrypt_ReadSectionNames("mycrypttest.ini")
If @error = 1 Then MsgBox(0, "Deleted", "'section1' deleted, then file would be empty now")

_IniCrypt_Shutdown() ; Used when you need to stop using or when you want to reset password/hash

 

 

Edited by robertocm

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