marcusvdt Posted November 26, 2024 Posted November 26, 2024 Hi 🙂 For some unknown reason, the same code behaves differently if I run it multiple times. Currently this is the most secure software ever as it seems like I must have the correct value for $myPASS and a lot of luck too 😁 The relevant part of the code: expandcollapse popup#include <Crypt.au3> #include <MsgBoxConstants.au3> global $special='[@#$%^&+=]' ConsoleWrite(@CRLF &@CRLF &'@@ Debug(' & @ScriptLineNumber & ') : TEST1' & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $StringToEncrypt="LA.Alalalala123123@" global $myPASS="LA.Alalalala123123@" $test=ENCRYPTit($StringToEncrypt,$myPASS) $test=DECRYPTit($test, $myPASS) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $test = ' & $test & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF &@CRLF &'@@ Debug(' & @ScriptLineNumber & ') : TEST2' & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $StringToEncrypt="AA.Alalalala123123@" $myPASS="LA.Alalalala123123@" $test=ENCRYPTit($StringToEncrypt,$myPASS) $test=DECRYPTit($test, $myPASS) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $test = ' & $test & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Func ENCRYPTit($StringToEncrypt,$myPASS) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : ENCRYPT' & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $myPASS = ' & $myPASS & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $StringToEncrypt = ' & $StringToEncrypt & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $hKey = _Crypt_DeriveKey(Binary(LOGIN($myPASS)), $CALG_AES_256,$CALG_SHA_512) ; Declare a password string and algorithm to create a cryptographic key. ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : Binary($hKey) = ' & Binary($hKey) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console local $encrypted = _Crypt_EncryptData($StringToEncrypt, Binary($hKey), $CALG_AES_256) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : binary($encrypted) = ' & binary($encrypted) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $encrypted = ' & $encrypted & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console _Crypt_DestroyKey($hKey) ; Destroy the cryptographic key. return Binary($encrypted) EndFunc Func DECRYPTit($StringToDecrypt, $myPASS) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : DECRYPT' & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $myPASS = ' & $myPASS & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $StringToDecrypt = ' & $StringToDecrypt & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $hKey = _Crypt_DeriveKey(Binary(LOGIN($myPASS)), $CALG_AES_256, $CALG_SHA_512) ; Declare a password string and algorithm to create a cryptographic key. ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : Binary($hKey) = ' & Binary($hKey) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $decrypted = _Crypt_DecryptData($StringToDecrypt, Binary($hKey), $CALG_AES_256) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : binary($decrypted) = ' & Binary($decrypted) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $decrypted = ' & $decrypted & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console _Crypt_DestroyKey($hKey) ; Destroy the cryptographic key. Return BinaryToString(binary($decrypted)) EndFunc ;==>DECRYPT Results when it fails: expandcollapse popup@@ Debug(6) : TEST1 >Error code: 0 @@ Debug(21) : ENCRYPT >Error code: 0 @@ Debug(22) : $myPASS = LA.Alalalala123123@ >Error code: 0 @@ Debug(23) : $StringToEncrypt = LA.Alalalala123123@ >Error code: 0 @@ Debug(25) : Binary($hKey) = 0xC0E709E4EC010000 >Error code: 0 @@ Debug(27) : binary($encrypted) = 0x13756D1C3845579E5CAE2065B087E3661165445612CFE4A40E18372BCA170DB1 >Error code: 0 @@ Debug(28) : $encrypted = 0x13756D1C3845579E5CAE2065B087E3661165445612CFE4A40E18372BCA170DB1 >Error code: 0 @@ Debug(35) : DECRYPT >Error code: 0 @@ Debug(36) : $myPASS = LA.Alalalala123123@ >Error code: 0 @@ Debug(37) : $StringToDecrypt = 0x13756D1C3845579E5CAE2065B087E3661165445612CFE4A40E18372BCA170DB1 >Error code: 0 @@ Debug(39) : Binary($hKey) = 0xC0E709E4EC010000 >Error code: 0 @@ Debug(41) : binary($decrypted) = 0x4C412E416C616C616C616C6131323331323340 >Error code: 0 @@ Debug(42) : $decrypted = 0x4C412E416C616C616C616C6131323331323340 >Error code: 0 @@ Debug(11) : $test = LA.Alalalala123123@ >Error code: 0 @@ Debug(13) : TEST2 >Error code: 0 @@ Debug(21) : ENCRYPT >Error code: 0 @@ Debug(22) : $myPASS = LA.Alalalala123123@ >Error code: 0 @@ Debug(23) : $StringToEncrypt = AA.Alalalala123123@ >Error code: 0 @@ Debug(25) : Binary($hKey) = 0xC0E709E4EC010000 >Error code: 0 @@ Debug(27) : binary($encrypted) = 0x0F2E2D69E210E72B7BEC05CF7E628A7D2D872D8F38B578AD046891BCBB8B044B >Error code: 0 @@ Debug(28) : $encrypted = 0x0F2E2D69E210E72B7BEC05CF7E628A7D2D872D8F38B578AD046891BCBB8B044B >Error code: 0 @@ Debug(35) : DECRYPT >Error code: 0 @@ Debug(36) : $myPASS = LA.Alalalala123123@ >Error code: 0 @@ Debug(37) : $StringToDecrypt = 0x0F2E2D69E210E72B7BEC05CF7E628A7D2D872D8F38B578AD046891BCBB8B044B >Error code: 0 @@ Debug(39) : Binary($hKey) = 0x40F209E4EC010000 >Error code: 0 @@ Debug(41) : binary($decrypted) = 0xFFFFFFFF >Error code: 0 @@ Debug(42) : $decrypted = -1 >Error code: 70 @@ Debug(18) : $test = ÿÿÿÿ >Error code: 0 +>19:17:42 AutoIt3.exe ended.rc:0 +>19:17:43 AutoIt3Wrapper Finished. >Exit code: 0 Time: 4.54 Another different failed try without any change in the code: expandcollapse popup@@ Debug(6) : TEST1 >Error code: 0 @@ Debug(21) : ENCRYPT >Error code: 0 @@ Debug(22) : $myPASS = LA.Alalalala123123@ >Error code: 0 @@ Debug(23) : $StringToEncrypt = LA.Alalalala123123@ >Error code: 0 @@ Debug(25) : Binary($hKey) = 0xA0E3B88EAA010000 >Error code: 0 @@ Debug(27) : binary($encrypted) = 0x8717DBB452965C093FD48B7B14C9DA4803A8D60A9189DBE97228503B3D098653 >Error code: 0 @@ Debug(28) : $encrypted = 0x8717DBB452965C093FD48B7B14C9DA4803A8D60A9189DBE97228503B3D098653 >Error code: 0 @@ Debug(35) : DECRYPT >Error code: 0 @@ Debug(36) : $myPASS = LA.Alalalala123123@ >Error code: 0 @@ Debug(37) : $StringToDecrypt = 0x8717DBB452965C093FD48B7B14C9DA4803A8D60A9189DBE97228503B3D098653 >Error code: 0 @@ Debug(39) : Binary($hKey) = 0x20F0B88EAA010000 >Error code: 0 @@ Debug(41) : binary($decrypted) = 0xFFFFFFFF >Error code: 0 @@ Debug(42) : $decrypted = -1 >Error code: 70 @@ Debug(11) : $test = ÿÿÿÿ >Error code: 0 @@ Debug(13) : TEST2 >Error code: 0 @@ Debug(21) : ENCRYPT >Error code: 0 @@ Debug(22) : $myPASS = LA.Alalalala123123@ >Error code: 0 @@ Debug(23) : $StringToEncrypt = AA.Alalalala123123@ >Error code: 0 @@ Debug(25) : Binary($hKey) = 0x20E1B88EAA010000 >Error code: 0 @@ Debug(27) : binary($encrypted) = 0xC993721623667138C0A2C523163694C08D35BDB55682AC3979AFF804CF914592 >Error code: 0 @@ Debug(28) : $encrypted = 0xC993721623667138C0A2C523163694C08D35BDB55682AC3979AFF804CF914592 >Error code: 0 @@ Debug(35) : DECRYPT >Error code: 0 @@ Debug(36) : $myPASS = LA.Alalalala123123@ >Error code: 0 @@ Debug(37) : $StringToDecrypt = 0xC993721623667138C0A2C523163694C08D35BDB55682AC3979AFF804CF914592 >Error code: 0 @@ Debug(39) : Binary($hKey) = 0xA0DEB88EAA010000 >Error code: 0 @@ Debug(41) : binary($decrypted) = 0xFFFFFFFF >Error code: 0 @@ Debug(42) : $decrypted = -1 >Error code: 70 @@ Debug(18) : $test = ÿÿÿÿ >Error code: 0 +>19:25:53 AutoIt3.exe ended.rc:0 +>19:25:53 AutoIt3Wrapper Finished. >Exit code: 0 Time: 3.022 Another try and different result again! expandcollapse popup@@ Debug(6) : TEST1 >Error code: 0 @@ Debug(21) : ENCRYPT >Error code: 0 @@ Debug(22) : $myPASS = LA.Alalalala123123@ >Error code: 0 @@ Debug(23) : $StringToEncrypt = LA.Alalalala123123@ >Error code: 0 @@ Debug(25) : Binary($hKey) = 0xC0EBD63F03020000 >Error code: 0 @@ Debug(27) : binary($encrypted) = 0x6916F4099537D771E17B8C970134D14EF369DEFA5937BBD5A995425023730D37 >Error code: 0 @@ Debug(28) : $encrypted = 0x6916F4099537D771E17B8C970134D14EF369DEFA5937BBD5A995425023730D37 >Error code: 0 @@ Debug(35) : DECRYPT >Error code: 0 @@ Debug(36) : $myPASS = LA.Alalalala123123@ >Error code: 0 @@ Debug(37) : $StringToDecrypt = 0x6916F4099537D771E17B8C970134D14EF369DEFA5937BBD5A995425023730D37 >Error code: 0 @@ Debug(39) : Binary($hKey) = 0x40EDD63F03020000 >Error code: 0 @@ Debug(41) : binary($decrypted) = 0xFFFFFFFF >Error code: 0 @@ Debug(42) : $decrypted = -1 >Error code: 70 @@ Debug(11) : $test = ÿÿÿÿ >Error code: 0 @@ Debug(13) : TEST2 >Error code: 0 @@ Debug(21) : ENCRYPT >Error code: 0 @@ Debug(22) : $myPASS = LA.Alalalala123123@ >Error code: 0 @@ Debug(23) : $StringToEncrypt = AA.Alalalala123123@ >Error code: 0 @@ Debug(25) : Binary($hKey) = 0xC0EBD63F03020000 >Error code: 0 @@ Debug(27) : binary($encrypted) = 0xB1FD73FE621D58CFE20D18386424EF788D4ED0528B9A95937C5FCABEE5BFB0F2 >Error code: 0 @@ Debug(28) : $encrypted = 0xB1FD73FE621D58CFE20D18386424EF788D4ED0528B9A95937C5FCABEE5BFB0F2 >Error code: 0 @@ Debug(35) : DECRYPT >Error code: 0 @@ Debug(36) : $myPASS = LA.Alalalala123123@ >Error code: 0 @@ Debug(37) : $StringToDecrypt = 0xB1FD73FE621D58CFE20D18386424EF788D4ED0528B9A95937C5FCABEE5BFB0F2 >Error code: 0 @@ Debug(39) : Binary($hKey) = 0xC0EBD63F03020000 >Error code: 0 @@ Debug(41) : binary($decrypted) = 0x41412E416C616C616C616C6131323331323340 >Error code: 0 @@ Debug(42) : $decrypted = 0x41412E416C616C616C616C6131323331323340 >Error code: 0 @@ Debug(18) : $test = AA.Alalalala123123@ >Error code: 0 +>19:29:06 AutoIt3.exe ended.rc:0 +>19:29:07 AutoIt3Wrapper Finished. >Exit code: 0 Time: 2.95 Then magically, after being insistent by running the same code again, it works: expandcollapse popup@@ Debug(6) : TEST1 >Error code: 0 @@ Debug(21) : ENCRYPT >Error code: 0 @@ Debug(22) : $myPASS = LA.Alalalala123123@ >Error code: 0 @@ Debug(23) : $StringToEncrypt = LA.Alalalala123123@ >Error code: 0 @@ Debug(25) : Binary($hKey) = 0x1095A7F58D010000 >Error code: 0 @@ Debug(27) : binary($encrypted) = 0x5DBA6E0DD474E2C394E9ADDD688C45333ABD5CD125510849B8CD60575015C146 >Error code: 0 @@ Debug(28) : $encrypted = 0x5DBA6E0DD474E2C394E9ADDD688C45333ABD5CD125510849B8CD60575015C146 >Error code: 0 @@ Debug(35) : DECRYPT >Error code: 0 @@ Debug(36) : $myPASS = LA.Alalalala123123@ >Error code: 0 @@ Debug(37) : $StringToDecrypt = 0x5DBA6E0DD474E2C394E9ADDD688C45333ABD5CD125510849B8CD60575015C146 >Error code: 0 @@ Debug(39) : Binary($hKey) = 0x1095A7F58D010000 >Error code: 0 @@ Debug(41) : binary($decrypted) = 0x4C412E416C616C616C616C6131323331323340 >Error code: 0 @@ Debug(42) : $decrypted = 0x4C412E416C616C616C616C6131323331323340 >Error code: 0 @@ Debug(11) : $test = LA.Alalalala123123@ >Error code: 0 @@ Debug(13) : TEST2 >Error code: 0 @@ Debug(21) : ENCRYPT >Error code: 0 @@ Debug(22) : $myPASS = LA.Alalalala123123@ >Error code: 0 @@ Debug(23) : $StringToEncrypt = AA.Alalalala123123@ >Error code: 0 @@ Debug(25) : Binary($hKey) = 0x1095A7F58D010000 >Error code: 0 @@ Debug(27) : binary($encrypted) = 0xAA6F0C080AB9D2582FFDB980409286CF25DA2CAA2D62995C2EEE0F82205FBDEF >Error code: 0 @@ Debug(28) : $encrypted = 0xAA6F0C080AB9D2582FFDB980409286CF25DA2CAA2D62995C2EEE0F82205FBDEF >Error code: 0 @@ Debug(35) : DECRYPT >Error code: 0 @@ Debug(36) : $myPASS = LA.Alalalala123123@ >Error code: 0 @@ Debug(37) : $StringToDecrypt = 0xAA6F0C080AB9D2582FFDB980409286CF25DA2CAA2D62995C2EEE0F82205FBDEF >Error code: 0 @@ Debug(39) : Binary($hKey) = 0x1095A7F58D010000 >Error code: 0 @@ Debug(41) : binary($decrypted) = 0x41412E416C616C616C616C6131323331323340 >Error code: 0 @@ Debug(42) : $decrypted = 0x41412E416C616C616C616C6131323331323340 >Error code: 0 @@ Debug(18) : $test = AA.Alalalala123123@ >Error code: 0 +>19:32:26 AutoIt3.exe ended.rc:0 +>19:32:26 AutoIt3Wrapper Finished. >Exit code: 0 Time: 3.397
Nine Posted November 26, 2024 Posted November 26, 2024 Maybe the problem comes from the LOGIN function ? Since you did not provide it, hard to say. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
spudw2k Posted November 26, 2024 Posted November 26, 2024 Two issues I see: No need to pass $hKey to the encrypt and decrypt functions as a binary You should use $CALG_USERKEY instead of $CALG_AES_256 ;local $encrypted = _Crypt_EncryptData($StringToEncrypt, Binary($hKey), $CALG_AES_256) local $encrypted = _Crypt_EncryptData($StringToEncrypt, $hKey, $CALG_USERKEY) ;Local $decrypted = _Crypt_DecryptData($StringToDecrypt, Binary($hKey), $CALG_AES_256) Local $decrypted = _Crypt_DecryptData($StringToDecrypt, $hKey, $CALG_USERKEY) Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
marcusvdt Posted November 27, 2024 Author Posted November 27, 2024 13 hours ago, Nine said: Maybe the problem comes from the LOGIN function ? Since you did not provide it, hard to say. Thank you for your answers, but this is not the case. If you look into the outputs, the login function is returning consistent values in all the tests.
marcusvdt Posted November 27, 2024 Author Posted November 27, 2024 10 hours ago, spudw2k said: Two issues I see: No need to pass $hKey to the encrypt and decrypt functions as a binary You should use $CALG_USERKEY instead of $CALG_AES_256 ;local $encrypted = _Crypt_EncryptData($StringToEncrypt, Binary($hKey), $CALG_AES_256) local $encrypted = _Crypt_EncryptData($StringToEncrypt, $hKey, $CALG_USERKEY) ;Local $decrypted = _Crypt_DecryptData($StringToDecrypt, Binary($hKey), $CALG_AES_256) Local $decrypted = _Crypt_DecryptData($StringToDecrypt, $hKey, $CALG_USERKEY) Thank you for your answer! It has resolved the issue. I just did not understand why I am forced to use $CALG_USERKEY instead of $CALG_AES_256. I thought there is where I choose which algorithm I want to use for encrypting/decrypting my stuff. If I can't choose it, why the help file for both the _Crypt_EncryptData and _Crypt_DecryptData tells that $iAlgID is "The algorithm to use. See _Crypt_DeriveKey()."? Also, do you know what is the practical effect of using $CALG_USERKEY?
spudw2k Posted November 27, 2024 Posted November 27, 2024 (edited) If you look inside the Crypt.au3 UDF, you can see that if $CALG_USERKEY is not specified, then the _Crypt_DeriveKey function is called anyways inside the _Crypt_EncryptData function with the key value and the algorithm chosen. You can think of it this way; the _Crypt_DeriveKey function embeds the encryption algorithm into the $hKey handle (HCRYPTKEY data type). So whether you generate (derive) a key on your own, or leave it to _Crypt_EncryptData to handle it for you, the algorithm is embedded in the HCRYPTKEY data type. The advantage of deriving a key on your own is that you can specify which hash algorithm you want to use. If you rely on having _Crypt_EncryptData handle the key derive function for you, it uses a default hash algo (MD5). The advantage of not deriving the key on your own is the key is automatically destroyed at the end of the _Crypt_EncryptData function, and you don't have to do it on your own. Edited November 27, 2024 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
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