EmilyLove Posted August 24, 2015 Share Posted August 24, 2015 (edited) Big thanks to CrypticKiwi for helping me with this issue. Click HERE to go to his solution. It was working earlier today but now all of a sudden it doesn't work. I literally have no idea why it won't work. It should look like 0x30783030453638434130 but it will only generate keys that looks like 0x016A0C08 now. (Hint: It's noticibly shorter)expandcollapse popup#RequireAdmin #include "crypt.au3" #include "Date.au3" #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 154, 121, 192, 124) $Label1 = GUICtrlCreateLabel("What would you like to do?", 8, 8, 141, 17) $Button1 = GUICtrlCreateButton("Encrypt", 8, 40, 137, 25) $Button2 = GUICtrlCreateButton("Decrypt", 8, 80, 137, 25) #EndRegion ### END Koda GUI section ### Global $key_encrypted = _Crypt_DeriveKey("1WSUJpOq1ca2H9DMRhs14iy3fI04IBFp", $CALG_RC4);Does not generate a working key. What's going on? Global $date, $input, $data, $result, $key GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1;I assume works as Intended. GUISetState(@SW_HIDE) $date = "" $date = _DateDiff("s", "1970/01/01 00:00:00", _NowCalc()) $data = "" $data = _Crypt_EncryptData($date, $key_encrypted, $CALG_RC4) $input = "" $input = InputBox("Crypter", "Enter the data to be encrypted.", $data) $result = "" $result = _Crypt_EncryptData($input, $key_encrypted, $CALG_RC4) InputBox("Crypter", "Your Data Encrypted is", $result) InputBox("Crypter", "Your Key Encrypted is", $key_encrypted) GUISetState(@SW_SHOW) Case $Button2;Works as Intended, as it decrypts previously successful encrypted variables just fine. GUISetState(@SW_HIDE) $input = "" $input = InputBox("Crypter", "Enter the data to be decrypted.") $key = "" $key = InputBox("Crypter", "Enter the key to decrypt the data.") $result = "" $result = BinaryToString(_Crypt_DecryptData($input, $key, $CALG_RC4)) InputBox("Crypter", "Your Data Decrypted is", $result) GUISetState(@SW_SHOW) EndSwitch WEnd Edited August 24, 2015 by BetaLeaf Fixed, Thanks CrypticKiwi CrypticKiwi 1 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 24, 2015 Moderators Share Posted August 24, 2015 BetaLeaf,The return you get from the _Crypt_DeriveKey function is a pointer to the generated key (check with VarGetType) - and as such I would expect it to look like "0x016A0C08" as that the normal format for that datatype. Why do you think it should be so much longer?M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
EmilyLove Posted August 24, 2015 Author Share Posted August 24, 2015 (edited) BetaLeaf,The return you get from the _Crypt_DeriveKey function is a pointer to the generated key (check with VarGetType) - and as such I would expect it to look like "0x016A0C08" as that the normal format for that datatype. Why do you think it should be so much longer?M23When I ran _Crypt_DeriveKey earlier that day, it gave me a much longer code that worked. This shorter code fails to properly decrypt the data I give it using _Crypt_DecryptData. Just to be clear, this script is just suppose to generate a key on boot and encrypt some data, with a function to check and make sure it can decrypt fine. Im using Windows 10 btw.For example I encrypted the word "test". It gave me the EncryptedData 0xBB34681Aand the key 0x026FBD20. Trying to decrypt it turns "test" into "[¿TÁ"Now you mentioned it is unexpected that the key is longer. Idk why you say that. This encrypted data contains my email, and it decrypts fine. Encrypted Data 0x5127F1C0426C24FCDE778CA6FA5B586F7F73Key 0x30783030453638434130 Edited August 24, 2015 by BetaLeaf example. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 24, 2015 Moderators Share Posted August 24, 2015 BetaLeaf,The function works fine for me:#include <Crypt.au3> #include <MsgBoxConstants.au3> Example() Func Example() Local $aStringsToEncrypt[5] = ["AutoIt", "SciTE", "Crypt", ".au3", "42"] Local $aEncryptedStrings[5], $aDecryptedStrings[5] Local $sEnCrypted = "", $sDeCrypted = "" Local $hKey = _Crypt_DeriveKey("CryptPassword", $CALG_RC4) ; Declare a password string and algorithm to create a cryptographic key. MsgBox($MB_SYSTEMMODAL, "Key Pointer", $hKey & @CRLF & @CRLF & VarGetType($hKey)) For $i = 0 To UBound($aStringsToEncrypt) - 1 $aEncryptedStrings[$i] = _Crypt_EncryptData($aStringsToEncrypt[$i], $hKey, $CALG_USERKEY) $sEnCrypted &= $aStringsToEncrypt[$i] & @TAB & " = " & $aEncryptedStrings[$i] & @CRLF ; Encrypt the text with the cryptographic key. $aDecryptedStrings[$i] = _Crypt_DecryptData($aEncryptedStrings[$i], $hKey, $CALG_USERKEY) $sDeCrypted &= $aEncryptedStrings[$i] & @TAB & " = " & BinaryToString($aDecryptedStrings[$i]) & @CRLF ; Encrypt the text with the cryptographic key. Next MsgBox($MB_SYSTEMMODAL, "Encrypted data", $sEnCrypted & @CRLF & @CRLF & $sDeCrypted) _Crypt_DestroyKey($hKey) ; Destroy the cryptographic key. EndFunc ;==>ExampleNow you mentioned it is unexpected that the key is longer. Idk why you say thatI say that because the returned value is a pointer and I would expect a pointer (on my 32 bit machine) to have the format 0x########. Were you perhaps running the script on a 64-bit machine when you got the longer return value?M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
EmilyLove Posted August 24, 2015 Author Share Posted August 24, 2015 I tried running in both 32 bit and 64 bit. The longer pointer seems to come from the 64 bit exe. I never build 64 bit exe so I have no idea why it did this. Also, I still cannot decrypt my test data with the code I posted in the OP Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 24, 2015 Moderators Share Posted August 24, 2015 BetaLeaf,The longer pointer seems to come from the 64 bit exeExactly - pointers are sized according to the "bitness" of OS on which they run. So that is one mystery solved.As to the failure to decrypt, please post the code (see here how to do it) that you are using to en/decrypt and we can see what might be the problem.M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
EmilyLove Posted August 24, 2015 Author Share Posted August 24, 2015 I already posted the problem script in the Original Post(OP). Link to comment Share on other sites More sharing options...
CrypticKiwi Posted August 24, 2015 Share Posted August 24, 2015 (edited) Got it, it has to be Number($Key) while recieving decryption input from inputboxexpandcollapse popup#RequireAdmin #include "crypt.au3" #include "Date.au3" #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 154, 121, 192, 124) $Label1 = GUICtrlCreateLabel("What would you like to do?", 8, 8, 141, 17) $Button1 = GUICtrlCreateButton("Encrypt", 8, 40, 137, 25) $Button2 = GUICtrlCreateButton("Decrypt", 8, 80, 137, 25) #EndRegion ### END Koda GUI section ### Global $key_encrypted = _Crypt_DeriveKey("1WSUJpOq1ca2H9DMRhs14iy3fI04IBFp", $CALG_RC4);Does not generate a working key. What's going on? Global $date, $input, $data, $result, $key GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1;I assume works as Intended. GUISetState(@SW_HIDE) $date = "" $date = _DateDiff("s", "1970/01/01 00:00:00", _NowCalc()) $data = "" $data = _Crypt_EncryptData($date, $key_encrypted, $CALG_RC4) $input = "" $input = InputBox("Crypter", "Enter the data to be encrypted.", $data) $result = "" $result = _Crypt_EncryptData($input, $key_encrypted, $CALG_RC4) InputBox("Crypter", "Your Data Encrypted is", $result) InputBox("Crypter", "Your Key Encrypted is", $key_encrypted) GUISetState(@SW_SHOW) Case $Button2;Works as Intended, as it decrypts previously successful encrypted variables just fine. GUISetState(@SW_HIDE) $input = "" $input = InputBox("Crypter", "Enter the data to be decrypted.") $key = "" $key = InputBox("Crypter", "Enter the key to decrypt the data.") $result = "" $result = BinaryToString(_Crypt_DecryptData($input, Number($key), $CALG_RC4)) InputBox("Crypter", "Your Data Decrypted is", $result) GUISetState(@SW_SHOW) EndSwitch WEnd Edited August 24, 2015 by CrypticKiwi EmilyLove 1 Link to comment Share on other sites More sharing options...
BrewManNH Posted August 24, 2015 Share Posted August 24, 2015 You're trying to encrypt the data with the derived key, but instead you're using the key as the password, which is wrong. Then you're expecting the user to remember the password used to decrypt it. If you want to use DeriveKey, then use $CALG_USERKEY as the algorithm for the encryption and decryption and not RC4. 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 GudeHow 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 Link to comment Share on other sites More sharing options...
EmilyLove Posted August 24, 2015 Author Share Posted August 24, 2015 Got it, it has to be Number($Key) while recieving decryption input from inputboxexpandcollapse popup#RequireAdmin #include "crypt.au3" #include "Date.au3" #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 154, 121, 192, 124) $Label1 = GUICtrlCreateLabel("What would you like to do?", 8, 8, 141, 17) $Button1 = GUICtrlCreateButton("Encrypt", 8, 40, 137, 25) $Button2 = GUICtrlCreateButton("Decrypt", 8, 80, 137, 25) #EndRegion ### END Koda GUI section ### Global $key_encrypted = _Crypt_DeriveKey("1WSUJpOq1ca2H9DMRhs14iy3fI04IBFp", $CALG_RC4);Does not generate a working key. What's going on? Global $date, $input, $data, $result, $key GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1;I assume works as Intended. GUISetState(@SW_HIDE) $date = "" $date = _DateDiff("s", "1970/01/01 00:00:00", _NowCalc()) $data = "" $data = _Crypt_EncryptData($date, $key_encrypted, $CALG_RC4) $input = "" $input = InputBox("Crypter", "Enter the data to be encrypted.", $data) $result = "" $result = _Crypt_EncryptData($input, $key_encrypted, $CALG_RC4) InputBox("Crypter", "Your Data Encrypted is", $result) InputBox("Crypter", "Your Key Encrypted is", $key_encrypted) GUISetState(@SW_SHOW) Case $Button2;Works as Intended, as it decrypts previously successful encrypted variables just fine. GUISetState(@SW_HIDE) $input = "" $input = InputBox("Crypter", "Enter the data to be decrypted.") $key = "" $key = InputBox("Crypter", "Enter the key to decrypt the data.") $result = "" $result = BinaryToString(_Crypt_DecryptData($input, Number($key), $CALG_RC4)) InputBox("Crypter", "Your Data Decrypted is", $result) GUISetState(@SW_SHOW) EndSwitch WEnd This works, Thank you very much CrypticKiwiYou're trying to encrypt the data with the derived key, but instead you're using the key as the password, which is wrong. Then you're expecting the user to remember the password used to decrypt it. If you want to use DeriveKey, then use $CALG_USERKEY as the algorithm for the encryption and decryption and not RC4.Could you show me an example of how it needs to be use to work properly so I may learn from it? I copy pasted the example from the documentation and expanded it to my needs. I thought I did it correctly. 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