Jump to content

Ini Crypt


SmOke_N
 Share

Recommended Posts

  • Moderators

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

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.

Link to comment
Share on other sites

  • 1 month later...

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

Link to comment
Share on other sites

  • 1 year later...

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

  • 4 years later...
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
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...