Jump to content

Encrypt a text from a file and ...


Recommended Posts

What i want to do :

- read a file that contains ini sections of an ini file but encrypted using a function (is there one for it ?)

- decrypt it and send the results to IniReadSection() (is it possible ?)

I don't know how to make a function for crypt/decrypt and i'm not sure about the IniReadSection() that usese a file as parameter and not a text from a variable.

In other words my file file.dat :

#$G%$##%^GHG

And using a function to decrypt it :

[section]

Key = Value

And then pass this to IniReadSection()

If u have other ideas for this tell me, please.

Link to comment
Share on other sites

there is already encrypt, and it has decrypt built in...

look in the help file for _StringEncrypt (under string management). it has it all there.

you probably want to save the converted cop to a temporary file, and then read that... unless you want to declare all the keys etc your self!! ^_^

Hope it helps

Mdiesel

Link to comment
Share on other sites

  • Moderators

OmYcroN,

Here is something from my snippets folder which you may find useful in your project:

#include <String.au3>

; define encryption settings
Global Const $enc_pass = "ABC123"; set the encryption password
Global Const $enc_level = 2; set the encryption level (check the help file for _StringEncrypt for possible levels)

; you can use the functions in a similar manner to the default IniWrite and IniRead
_IniWrite("data.ini", "settings", "foo", "bar")
ConsoleWrite(_IniRead("data.ini", "settings", "foo", "OOPS!") & @CRLF)

; just like the default IniWrite
Func _IniWrite($sIniPath, $sIniSection, $sIniKey, $sIniValue)
    IniWrite($sIniPath, $sIniSection, $sIniKey, _StrEncrypt($sIniValue))
EndFunc  ;==>_IniWrite

; just like the default IniRead
Func _IniRead($sIniPath, $sIniSection, $sIniKey, $sIniDefault)
    Return _StrDecrypt(IniRead($sIniPath, $sIniSection, $sIniKey, _StrEncrypt($sIniDefault)))
EndFunc  ;==>_IniRead

; Encrypt a string using the default $enc_pass and $enc_level
Func _StrEncrypt($sString)
    Return _StringEncrypt(1, $sString, $enc_pass, $enc_level)
EndFunc  ;==>_StrEncrypt

; Decrypt a string using the default $enc_pass and $enc_level
Func _StrDecrypt($sString)
    Return _StringEncrypt(0, $sString, $enc_pass, $enc_level)
EndFunc  ;==>_StrDecrypt

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

OmYcroN,

Here is something from my snippets folder which you may find useful in your project:

#include <String.au3>

; define encryption settings
Global Const $enc_pass = "ABC123"; set the encryption password
Global Const $enc_level = 2; set the encryption level (check the help file for _StringEncrypt for possible levels)

; you can use the functions in a similar manner to the default IniWrite and IniRead
_IniWrite("data.ini", "settings", "foo", "bar")
ConsoleWrite(_IniRead("data.ini", "settings", "foo", "OOPS!") & @CRLF)

; just like the default IniWrite
Func _IniWrite($sIniPath, $sIniSection, $sIniKey, $sIniValue)
    IniWrite($sIniPath, $sIniSection, $sIniKey, _StrEncrypt($sIniValue))
EndFunc ;==>_IniWrite

; just like the default IniRead
Func _IniRead($sIniPath, $sIniSection, $sIniKey, $sIniDefault)
    Return _StrDecrypt(IniRead($sIniPath, $sIniSection, $sIniKey, _StrEncrypt($sIniDefault)))
EndFunc ;==>_IniRead

; Encrypt a string using the default $enc_pass and $enc_level
Func _StrEncrypt($sString)
    Return _StringEncrypt(1, $sString, $enc_pass, $enc_level)
EndFunc ;==>_StrEncrypt

; Decrypt a string using the default $enc_pass and $enc_level
Func _StrDecrypt($sString)
    Return _StringEncrypt(0, $sString, $enc_pass, $enc_level)
EndFunc ;==>_StrDecrypt

M23

mdiesel : Thank u for the idea ... i did like u said

M23 : Thanks for the code ... I can only say that _StringEncrypt takes a LOT of time for encrypting 30kb of plain text

Many thanks to both.

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...