grasshopper3 Posted May 19, 2010 Share Posted May 19, 2010 (edited) I am trying to encrypt a comma delimited string. When I try to decrypt it, it isn't giving the correct string. Its something like "yyyy". Does anyone know a solution. #include <Crypt.au3> $string = ',,hello,world,,' MsgBox(0,'', _Crypt_EncryptData($string, "123", $CALG_AES_256)) MsgBox(0,'', BinaryToString(_Crypt_DecryptData($string, "123",$CALG_AES_256))) UPDATE: I figured out why I was getting "yyyy". It was because it was trying to BinaryToString(-1) which is returned by _Crypt_DecryptData(). I am still not sure why it is unable to decrypt the string correctly. Edited May 19, 2010 by grasshopper3 Link to comment Share on other sites More sharing options...
JohnOne Posted May 19, 2010 Share Posted May 19, 2010 #include <Crypt.au3> $string = ',,hello,world,,' $crypt = _Crypt_EncryptData($string, "123", $CALG_AES_256) MsgBox(0,'', $crypt) MsgBox(0,'', BinaryToString(_Crypt_DecryptData($crypt,"123",$CALG_AES_256))) AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 19, 2010 Share Posted May 19, 2010 UPDATE:I figured out why I was getting "yyyy". It was because it was trying to BinaryToString(-1) which is returned by _Crypt_DecryptData(). I am still not sure why it is unable to decrypt the string correctly.Look closer at the example from JohnOne. Your problem is that you didn't save the encrypted value anywhere. The function _Crypt_EncryptData($string, "123", $CALG_AES_256) returns the encrypted data, it does not modify $string. So the problem is that you are trying to decrypt the unencrypted data with _Crypt_DecryptData($string, "123",$CALG_AES_256). Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
grasshopper3 Posted May 19, 2010 Author Share Posted May 19, 2010 Yea, I noticed that after he posted my example was terrible, but it cause me to double check my actual script and I found the problem. It was a similar stupid mistake. Thanks. Link to comment Share on other sites More sharing options...
grasshopper3 Posted May 21, 2010 Author Share Posted May 21, 2010 ever since I implemented this into my script it has been causing trouble. I will encrypt a string and it is written into the .log like... ¾£{Њ…Eqo#“BÀ<kªå,jlË•?0(kåæ6. This causes an error when trying to decrypt. I have put msgboxes on the filewriteline() to preview what it is writing and it doesn't look like the above, it looks correct 38A9CC7FE2E499EDDE3DFFC24A. Does any one have an idea of what is going on? Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 21, 2010 Share Posted May 21, 2010 (edited) The binary is being automatically converted to an ASCII string of hex code for your viewing. If you want to save the values, it must be in a binary file, i.e. opened with: #include <Crypt.au3> Global $sString, $bCrypted, $bDecrypted, $sDecrypted Global $sFile = @ScriptDir & "\Test1.bin", $hFile, $bData $sString = ',,hello,world,,' ConsoleWrite("Original $sString = " & $sString & " ; Type = " & VarGetType($sString) & @LF) $bCrypted = _Crypt_EncryptData($sString, "123", $CALG_AES_256) ConsoleWrite("Encrypted $bCrypted = " & $bCrypted & " ; Type = " & VarGetType($bCrypted) & @LF) $hFile = FileOpen($sFile, 16 + 2) ; Binary + overwrite FileWrite($hFile, $bCrypted) FileClose($hFile) $hFile = FileOpen($sFile, 16) ; Binary read $bData = FileRead($hFile) FileClose($hFile) ConsoleWrite("File data $bData = " & $bData & " ; Type = " & VarGetType($bData) & @LF) $bDecrypted = _Crypt_DecryptData($bData, "123", $CALG_AES_256) ConsoleWrite("Decrypted $bDecrypted = " & $bDecrypted & " ; Type = " & VarGetType($bDecrypted) & @LF) $sDecrypted = BinaryToString($bDecrypted) ConsoleWrite("String $sDecrypted = " & $sDecrypted & " ; Type = " & VarGetType($sDecrypted) & @LF) If you want to mix it in with other textual data, then you'll have to do your own conversion to "0xFEDCBA9876543210" format. Edit: Forgot write mode for FileOpen() Edit2: Expanded demo script Edited May 21, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
grasshopper3 Posted May 21, 2010 Author Share Posted May 21, 2010 (edited) The binary is being automatically converted to an ASCII string of hex code for your viewing. If you want to save the values, it must be in a binary file, i.e. opened with: $hBinFile = FileOpen($sFileName, 16) ; 16 = binary FileWrite($hFile, $binCrptData) FileClose($hFile) If you want to mix it in with other textual data, then you'll have to do your own conversion to "0xFEDCBA9876543210" format. I didn't say earlier, but this doesn't occur every time; only every other. Would this still be the solution if it works sometimes? Update: I tried your solution and it got worst $Data= _Crypt_EncryptData($Data, "123", $CALG_AES_256) $File = FileOpen(@ScriptDir & "\settings.ini",18) FileWriteLine($File,$Data) FileClose($File) Update: fixed it with FileWriteLine($File,StringToBinary($SetStrings)) Edited May 21, 2010 by grasshopper3 Link to comment Share on other sites More sharing options...
PsaltyDS Posted May 21, 2010 Share Posted May 21, 2010 I didn't say earlier, but this doesn't occur every time; only every other. Would this still be the solution if it works sometimes? Update: I tried your solution and it got worst $Data= _Crypt_EncryptData($Data, "123", $CALG_AES_256) $File = FileOpen(@ScriptDir & "\settings.ini",18) FileWriteLine($File,$Data) FileClose($File) Update: fixed it with FileWriteLine($File,StringToBinary($SetStrings)) Yeah, I expanded the example in my post to include that. Note that _Crypt_EncryptData() is treating the input $Data as a binary too. To strictly type your variables correctly, you would do StringToBinary() on the input before encrypting also. AutoIt's built-in recasting hides that from you a little. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
JSBGAMES Posted January 29, 2017 Share Posted January 29, 2017 Hello everyone, I'm having problems, I updated my autoit to the version: 3.3.14.2 and my script did not want to work anymore, I'll post it so that you can help me. #include <String.au3> Local $numero_serial="" Local $serial_guardado="" Local $Senha="" $Senha = IniRead("C:\ID.ini","activation","key","0") $numero_serial = IniRead("C:\ID.ini","activation","number","0") $serial_guardado = IniRead("C:\ID.ini","activation","activation","0") $numero_serial = _StringEncrypt (1, $numero_serial, $Senha,1) If StringCompare($numero_serial, $serial_guardado) <> 0 Then ShellExecute("C:\ID.exe") Exit EndIf Link to comment Share on other sites More sharing options...
Subz Posted January 29, 2017 Share Posted January 29, 2017 As per the helpfile Script Breaking Changes in Recent Versions v3.3.10.0 AutoIt: UDFs: _StringEncrypt() documentation has been removed. The function is still present in String.au3, but may be removed at a later date. Scripts should be updated to use the Crypt functions instead. Look at _Crypt_EncryptData() for an example of an alternative _StringEncrypt. Link to comment Share on other sites More sharing options...
JSBGAMES Posted January 30, 2017 Share Posted January 30, 2017 (edited) @Subz Before it was a mistake, now it does not work, what can it be? I have already modified several things and nothing. #include <String.au3> #include <Crypt.au3> Local $numero_serial="" Local $serial_guardado="" Local $Senha="" $Senha = IniRead("C:\ID.ini","activation","key","0") $numero_serial = IniRead("C:\ID.ini","activation","number","0") $serial_guardado = IniRead("C:\ID.ini","activation","activation","0") $numero_serial = _Crypt_EncryptData (1, $numero_serial, $Senha,1) If StringCompare($numero_serial, $serial_guardado) <> 0 Then ShellExecute("C:\ID.exe") Exit EndIf Edited January 30, 2017 by JSBGAMES Link to comment Share on other sites More sharing options...
JSBGAMES Posted January 30, 2017 Share Posted January 30, 2017 (edited) I managed to solve !!!!, the only detail would be to make that the encrypted number example 0x4af07c668ec0 was generated without the 0x only 4af07c668ec0 what would have to modify to work the way I want? #include <Crypt.au3> #include <String.au3> #include <MsgBoxConstants.au3> Local $numero_serial ="" Local $serial_guardado ="" Local $Senha ="" $Senha = IniRead("C:\ID.ini","activation","key","0") $numero_serial = IniRead("C:\ID.ini","activation","number","0") $serial_guardado = IniRead("C:\ID.ini","activation","activation","0") $numero_serial = _Crypt_EncryptData ($numero_serial, $Senha,$CALG_rc4) MsgBox(0,'', $numero_serial) MsgBox(0,'', BinaryToString(_Crypt_DecryptData($numero_serial,$Senha,$CALG_rc4))) If StringCompare($NUMERO_SERIAL, $SERIAL_GUARDADO) <> 0 Then SplashTextOn("", "errado", 160, 50, -1, -1, 1, "", 18) Sleep(2000) Else SplashTextOn("", "correto", 160, 50, -1, -1, 1, "", 18) Sleep(2000) EndIf Edited January 30, 2017 by JSBGAMES Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now