Jump to content
tonycst

How to fix outdaed _StringEncrypt ?

Recommended Posts

tonycst

How to update this line to make the code work again ?

_StringEncrypt (0, $StringToEncrypt, $EnryptionPassword , 2 )

What parameter does what in the old version ? Are encryption algorithms the same ?
Cant find much help in help file. All it says is that its outdated and will be removed.

Share this post


Link to post
Share on other sites
TheXman

Have you taken a look at _Crypt_EncryptData()?

Share this post


Link to post
Share on other sites
KickStarter15

Try checking with _Crypt function and check with "_Crypt_EncryptData()" to replace your _StringEncrypt(). Also, the StringEncrypt() function was included from the help examples.


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
tonycst
7 minutes ago, TheXman said:

Have you taken a look at _Crypt_EncryptData()?

I did.

I dont understand some things.

What does 0 and 2 stand for in the old version ?

The string to encrypt and the password are eazy, but what do those numbers stand for ?

Share this post


Link to post
Share on other sites
TheXman

Looks like the function was removed way back in version 3.3.9.8.  It's not in any of the the versions that I have installed.  If you can find a pre-3.3.9.8 version, I'm sure the help file and include file will document it.

 

You can go here to find older versions: https://www.autoitscript.com/autoit3/files/archive/autoit/

Edited by TheXman
Added link to old versions

Share this post


Link to post
Share on other sites
KickStarter15
11 minutes ago, tonycst said:

What does 0 and 2 stand for in the old version ?

- The value for 0 is to decrypt and 1 is to encrypt.

- The value for 2 is the level of encrypt/decrypt, mostly the default value for this is "1" if i'm not mistaken.

You can add the level by declaring an $inputlevel.


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
tonycst

Found it thanks !
0 for decrypt (1 to encrypt) and  2 stands for LEVEL of encryption but not algorithm.
But what do i do with the script now that instead of level is asking for algorithm ?

Share this post


Link to post
Share on other sites
TheXman

Here's the UDF header for the command.

 

; #FUNCTION# ====================================================================================================================
; Name...........: _StringEncrypt
; Description ...: An RC4 based string encryption function.
; Syntax.........: _StringEncrypt($i_Encrypt, $s_EncryptText, $s_EncryptPassword[, $i_EncryptLevel = 1])
; Parameters ....: $i_Encrypt         - 1 to encrypt, 0 to decrypt.
;                  $s_EncryptText     - Text to encrypt/decrypt.
;                  $s_EncryptPassword - Password to encrypt/decrypt with.
;                  $i_EncryptLevel    - Optional: Level to encrypt/decrypt. Default = 1
; Return values .: Success - The Encrypted/Decrypted string.
;                  Failure - Blank string and @error = 1
; Author ........: Wes Wolfe-Wolvereness <Weswolf at aol dot com>
; Modified.......:
; Remarks .......: WARNING: This function has an extreme timespan if the encryption level or encrypted string are too large!
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================

 

 

 

 

Share this post


Link to post
Share on other sites
tonycst

yeah i get it.

My old script (not mine) says to encrypt level 2 (not default)

Does level 2 translates to  $CALG_RC4 or what ?

Share this post


Link to post
Share on other sites
TheXman
15 minutes ago, tonycst said:

Does level 2 translates to  $CALG_RC4 or what ?

No. 

The old _StringEncrypt function used RC4 for its encyption.  The new _Crypt functions allow you to choose from several different enrcyption algorithms. For _StringEncrypt, to the best of my recollection, the level of encryption is basically how many times it looped through the encryption algorithm.  So if you use a level of 2 to encrypt, then you need to use a level of 2 to successfully decrypt.

Let's step back.  Are you trying to use the _StringEncrypt/Decrypt functions with an AutoIt version newer than 3.3.9.8? If so, then you will need to rewrite the encryption routine to use the Crypt.au3 UDF.  It is not a direct replacement.  If you are still using the old version of AutoIt, then I don't understand what your issue is now that you know what the parameters are.

 

 

Edited by TheXman

Share this post


Link to post
Share on other sites
tonycst

I am using slightly modified UDF from

Fixing code such as:

Global $R3 = _StringEncrypt (1,$R2,$EnryptionPassword)             ;Encrypt
With
Global $R3 = _Crypt_EncryptData ($EnryptionPassword,$R2,$CALG_RC4)    ;Encrypt

does not seem to work in the end.
Function its self does work, but the UDF is not functioning correctly for some reasons.

Share this post


Link to post
Share on other sites
TheXman

The _crypt commands are not a direct replacement for the old _StringEncrypt/Decrypt.  The newer _Crypt functions return a binary string for one.  Secondly, if you want to do multiple levels of encryption/decryption, then you will need to code the iterations yourself.  The newer _Crypt functions will most likely take a little more code to give you the same results as the older _String command.

It appears that you may need to take some time to learn how the newer _crypt functions work and the difference between them and the old _StringEncrypt and _StringDecrypt.

Share this post


Link to post
Share on other sites
tonycst

How do i convert that binary to a regular string ?
Thats why script fails i guess. ITs expecting regular string.

thanks for that info

Share this post


Link to post
Share on other sites
tonycst
11 minutes ago, TheXman said:

The _crypt commands are not a direct replacement for the old _StringEncrypt/Decrypt.  The newer _Crypt functions return a binary string for one.  Secondly, if you want to do multiple levels of encryption/decryption, then you will need to code the iterations yourself.  The newer _Crypt functions will most likely take a little more code to give you the same results as the older _String command.

It appears that you may need to take some time to learn how the newer _crypt functions work and the difference between them and the old _StringEncrypt and _StringDecrypt.

BinaryToString ( _Crypt_EncryptData ($EnryptionPassword,$R2,$CALG_RC4) )

That KINDA works. It returns weird characters such as

ï°;

But script works somewhat. Script now goes thru activation process etc and even keygen works, but for some reasons activation is not remembered.

I am assuming its because those strange characters such as ï°; and ¼9¼ are just not getting written into either ini or registry correctly.

 

 

What type of binary does _Crypt return ?
Help file on binarytostring says:

[optional] Changes how the binary data is converted:
    $SB_ANSI (1) = binary data is ANSI (default)
    $SB_UTF16LE (2) = binary data is UTF16 Little Endian
    $SB_UTF16BE (3) = binary data is UTF16 Big Endian
    $SB_UTF8 (4) = binary data is UTF8

But i dont know which one i need.

Edited by tonycst

Share this post


Link to post
Share on other sites
TheXman

Without seeing the code, I'm flying blind here.  Most likely, BinaryToString() is not what you want to use to store the encrypted value because the encrypted value is not a text string.  However, BinaryToString() is what you will probably want to use when decrypting the value return by _Crypt_DecryptData().  Depending on where the encrypted value is being stored (registry, ini, etc) will probably dictate whether you need to save the binary result as binary or its text representation.  If it is saved to the registry, then you can either save it as binary or convert it to text.  If it is an ini file or other text based file, then you will probably want to convert it to a readable (text) format by using the String() function or some other function that converts binary to hex string representation.  For example, String($binaryValue) would convert the binary to a hex string.  I have no idea what your code was doing before so I can't help in terms of pointing you in the right direction.

I just looked at the scripts you referenced earlier.  It appears they are storing values in an ini file.  Below, is a brief example of encrypting and decrypting a known string.  You can see how and where the binary is being converted to either a hex string (for storage) or an actual string (decryption).

#include <Constants.au3>
#include <Crypt.au3>


Encrypt_Example()
Decrypt_Example()

;==========================================================================
;
;==========================================================================
Func Encrypt_Example()

    Const $kStringToEncrypt = "Encrypt me"
    Local $dEncryptedValue  = Binary("")

    $dEncryptedValue = _Crypt_EncryptData($kStringToEncrypt, "Super Secret", $CALG_RC4)
    If @error Then
        MsgBox($MB_ICONERROR, "Encryption Error", StringFormat("@error = %s", @error))
        Exit 1
    EndIf

    ; A couple of ways to show the binary result as a hex string
    ConsoleWrite(@CRLF)
    ConsoleWrite(StringFormat("String to encrypt              = %s", $kStringToEncrypt) & @CRLF)
    ConsoleWrite(StringFormat("$dEncryptedValue as hex string = %s", $dEncryptedValue) & @CRLF) ; one way to show it
    ConsoleWrite("$dEncryptedValue as hex string = " & String($dEncryptedValue) & @CRLF)        ; a different way to show it

EndFunc

;==========================================================================
;
;==========================================================================
Func Decrypt_Example()

    Local $dEncryptedValue = Binary("0x5A588A3D5D5EB8892B41"), _
          $dDecryptedValue = Binary("")

    $dDecryptedValue = _Crypt_DecryptData($dEncryptedValue, "Super Secret", $CALG_RC4)
    If @error Then
        MsgBox($MB_ICONERROR, "Decryption Error", StringFormat("@error = %s", @error))
        Exit 1
    EndIf

    ; Show the binary result as a hex string
    ConsoleWrite(@CRLF)
    ConsoleWrite(StringFormat("$dDecryptedValue as hex string = %s", $dDecryptedValue) & @CRLF) ; one way to show it

    ; Convert the binary result to a string
    ConsoleWrite(StringFormat("$dDecryptedValue as string     = %s", BinaryToString($dDecryptedValue)) & @CRLF) ; one way to show it

EndFunc

 

Edited by TheXman

Share this post


Link to post
Share on other sites
tonycst

Yes.

It was one issue when i had to rewrite encrypting and decrypting functions, but i now also have to figure out what parts of the code need to have decryption for comparison to be converted into a string and what parts dont.

Sucks oh well, i learned something new again.

Truly :D SCRIPT BREAKING CHANGE lol

Edited by tonycst

Share this post


Link to post
Share on other sites
Zedna

Download that old version of AutoIt in ZIP format.

Exctract from its include file (Strig.au3) your old _StringEncrypt() function and copy it to your new script.

Now use it (call it) in its original syntax so you will be able also decrypt previous binary coded external saved strings.

Share this post


Link to post
Share on other sites
tonycst

I ended up rewriting all of those functions just reusing variables it had.

I learned allot.
Love this forum, very helpful.

Just wish sometimes very old topics would not get locked by mods. Just because they are old, does not mean issues are not current. (off tipic)

Share this post


Link to post
Share on other sites
Melba23

tonycst,

Quote

Just wish sometimes very old topics would not get locked by mods. Just because they are old, does not mean issues are not current

So start a new thread and link to the old one., That way if the original code is no longer useable after several AutoIt updates it does not confuse anyone.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
BrewManNH
15 hours ago, tonycst said:

Just wish sometimes very old topics would not get locked by mods. Just because they are old, does not mean issues are not current. (

If the thread was about _StringEncrypt, then it's not current because that function isn't supported any longer. If it's about any other function that has been updated to a newer version, or removed then it should be locked because you should update.


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

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

×