spudw2k Posted December 10, 2009 Share Posted December 10, 2009 Are you reading the file raw/binary? 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 BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
RogFleming Posted December 10, 2009 Share Posted December 10, 2009 Are you reading the file raw/binary? The question puzzled me for a second, let me give you the total picture. I have a GUI which I ask the user to provide challenge/response questions for the user to fill in and will be presented with the questions in the future if the user forgets their password. The process of uploading/and downloading the challenge and response is using LDAP to a LDAP directory store. So based on your question, I guess the encrypted answer when it comes back from the LDAP query must be raw, which then I guessing I need to tell the program to change it to binary. I can do that and test it. Func AES_Encrypt($userid,$data) $bindata = Binary($data) _FileWriteLog("\\10.240.52.109\Log\SSPP.log",$userid&" "&"Binary Input Data"&" : "&$bindata) $Encrypted = _AesEncrypt("95A8EE8E89979B9EFDCBC6EB9797528D432DC26061553818EA635EC5D5A7727E", $bindata, "CBC") _FileWriteLog("\\10.240.52.109\Log\SSPP.log",$userid&" "&"Encrypting Data"&" : "&$Encrypted) AES_Decrypt($userid,$Encrypted) Return $Encrypted EndFunc Func AES_Decrypt($userid,$data) _FileWriteLog("\\10.240.52.109\Log\SSPP.log",$userid&" "&"Decrypted input"&" : "&$data) $Decrypted = _AesDecrypt("95A8EE8E89979B9EFDCBC6EB9797528D432DC26061553818EA635EC5D5A7727E", $data, "CBC") _FileWriteLog("\\10.240.52.109\Log\SSPP.log",$userid&" "&"Decrypted output1"&" : "&$Decrypted) $Result = BinaryToString($Decrypted) _FileWriteLog("\\10.240.52.109\Log\SSPP.log",$userid&" "&"Decrypted output2"&" : "&$Result) Return $Result EndFunc Link to comment Share on other sites More sharing options...
RogFleming Posted December 10, 2009 Share Posted December 10, 2009 Are you reading the file raw/binary? To answer the question is the data is coming back RAW, if I try to change it binary the number changes. and the garbage data returns. Func AES_Decrypt($userid,$data) $data = Binary($data) ;change to binary $bin = IsBinary($data) ; checks for binary data If $bin = 1 Then _FileWriteLog("\\10.240.52.109\Log\SSPP.log",$userid&" "&"data was binary"&" : "&$bin) $Decrypted = _AesDecrypt("95A8EE8E89979B9EFDCBC6EB9797528D432DC26061553818EA635EC5D5A7727E", $data) _FileWriteLog("\\10.240.52.109\Log\SSPP.log",$userid&" "&"Decrypted output1"&" : "&$Decrypted&" Binary Size:"&BinaryLen($Decrypted)) $Result = BinaryToString($Decrypted) _FileWriteLog("\\10.240.52.109\Log\SSPP.log",$userid&" "&"Decrypted output2"&" : "&$Result) Return $Result Else _FileWriteLog("\\10.240.52.109\Log\SSPP.log",$userid&" "&"no binary data was found"&" : "&$bin) EndIf EndFunc Link to comment Share on other sites More sharing options...
RogFleming Posted December 10, 2009 Share Posted December 10, 2009 Are you reading the file raw/binary? almost forgot the encrypted values are coming from an Array which is the output from the LDAP query. Local $eArray1 = GetDirObj($userid,"question1","sn","userPassword") Local $data1 = _ArrayToString($eArray1," ",8,8); The 8th element is the encrypted password $decrypt_data1 = AES_Decrypt($userid,$data1) Local $eArray2 = GetDirObj($userid,"question2","sn","userPassword") ocal $data2 = _ArrayToString($eArray2," ",8,8) $decrypt_data2 = AES_Decrypt($userid,$data2) Local $eArray3 = GetDirObj($userid,"question3","sn","userPassword") Local $data3 = _ArrayToString($eArray3," ",8,8) $decrypt_data3 = AES_Decrypt($userid,$data3) Link to comment Share on other sites More sharing options...
wraithdu Posted December 10, 2009 Share Posted December 10, 2009 (edited) To correctly convert your retrieved password to binary, you need to prefix the string with 0x, ie $data1 = Binary("0x" & $data1) Example: $data = "12345678" ; wrong ConsoleWrite(Binary($data) & @CRLF) ; right ConsoleWrite(Binary("0x" & $data) & @CRLF) Edited December 10, 2009 by wraithdu Link to comment Share on other sites More sharing options...
RogFleming Posted December 10, 2009 Share Posted December 10, 2009 No good: Local $eArray1 = GetDirObj($userid,"question1","sn","userPassword") Local $data1 = _ArrayToString($eArray1," ",8,8) Local $data1 = Binary("0x" & $data1) ; data1 from array looked like this '0xC32DF6F1D85E609E2C3B7871718955C7C443' _FileWriteLog("\\10.240.52.109\Log\SSPP.log",$userid&" "&"Binary Input Data"&" : "&$data1) $decrypt_data1 = AES_Decrypt($userid,$data1) _FileWriteLog("\\10.240.52.109\Log\SSPP.log",$userid&" "&"Encrypted Binary Output Data"&" : "&$decrypt_data1) Log file reports: 2009-12-10 15:48:43 : fleminr Users encrypted answer was retrieved from Directory. : 0xC32DF6F1D85E609E2C3B7871718955C7C443 2009-12-10 15:48:43 : fleminr Users encrypted answer was retrieved from Directory. : 0x9679D5119C239348A0C56A95F7A5C458BBE8 2009-12-10 15:48:43 : fleminr Users encrypted answer was retrieved from Directory. : 0x49F5392353DC01C540CCBDB966D394E30C03 2009-12-10 15:48:49 : fleminr Binary Input Data : 2009-12-10 15:48:49 : fleminr data was binary : 2009-12-10 15:48:49 : fleminr Decrypted output1 : 2009-12-10 15:48:49 : fleminr Decrypted output2 : 2009-12-10 15:48:49 : fleminr Encrypted Binary Output Data : My guess is to trim the string value to remove 0x before the function you suggested? Link to comment Share on other sites More sharing options...
SkinnyWhiteGuy Posted December 10, 2009 Share Posted December 10, 2009 Are you receiving 3 encrypted responses? Or is the 1 response split up? You may not have all data needed. Link to comment Share on other sites More sharing options...
RogFleming Posted December 10, 2009 Share Posted December 10, 2009 I have the solution thanks for the help: Func AES_Decrypt($userid,$data) $Decrypted = _AesDecrypt("95A8EE8E89979B9EFDCBC6EB9797528D432DC26061553818EA635EC5D5A7727E", $data) _FileWriteLog("\\10.240.52.109\Log\SSPP.log",$userid&" "&"Decrypted output1"&" : "&$Decrypted) $Result = BinaryToString($Decrypted) _FileWriteLog("\\10.240.52.109\Log\SSPP.log",$userid&" "&"Decrypted output2"&" : "&$Result) Return $Result EndFunc Local $eArray1 = GetDirObj($userid,"question1","sn","userPassword") Local $data1 = _ArrayToString($eArray1," ",8,8) _FileWriteLog("\\10.240.52.109\Log\SSPP.log",$userid&" "&"Retrieved password data from array"&" : "&$data1) Local $data2 = StringTrimLeft ( $data1, 3) _FileWriteLog("\\10.240.52.109\Log\SSPP.log",$userid&" "&"String was trimed left 2 characters"&" : "&$data2) Local $data3 = Binary("0x" & $data2) _FileWriteLog("\\10.240.52.109\Log\SSPP.log",$userid&" "&"Binary Input Data"&" : "&$data3) $decrypt_data1 = AES_Decrypt($userid,$data3) _FileWriteLog("\\10.240.52.109\Log\SSPP.log",$userid&" "&"Encrypted Binary Output Data"&" : "&$decrypt_data1) Logs 2009-12-10 16:02:23 : fleminr Users encrypted answer was retrieved from Directory. : 0xC32DF6F1D85E609E2C3B7871718955C7C443 2009-12-10 16:02:23 : fleminr Users encrypted answer was retrieved from Directory. : 0x9679D5119C239348A0C56A95F7A5C458BBE8 2009-12-10 16:02:24 : fleminr Users encrypted answer was retrieved from Directory. : 0x49F5392353DC01C540CCBDB966D394E30C03 2009-12-10 16:02:30 : fleminr Retrieved password data from array : 0xC32DF6F1D85E609E2C3B7871718955C7C443 2009-12-10 16:02:30 : fleminr String was trimed left 3 characters : C32DF6F1D85E609E2C3B7871718955C7C443 2009-12-10 16:02:30 : fleminr Binary Input Data : 0xC32DF6F1D85E609E2C3B7871718955C7C443 2009-12-10 16:02:30 : fleminr Decrypted output1 : 0x6131 2009-12-10 16:02:30 : fleminr Decrypted output2 : a1 2009-12-10 16:02:30 : fleminr Encrypted Binary Output Data : a1 My only question or the root issue was that the ArraytoString might have brought a white space in front of the data, which might have been why it was not seen as a binary value in the first place. I will test that right now. Link to comment Share on other sites More sharing options...
SkinnyWhiteGuy Posted December 10, 2009 Share Posted December 10, 2009 If so, StringTrimWhiteSpace($string, 3) could clean it up on both ends, before you call Binary. Link to comment Share on other sites More sharing options...
RogFleming Posted December 10, 2009 Share Posted December 10, 2009 2009-12-10 16:11:13 : fleminr Users encrypted answer was retrieved from Directory. : 0xC32DF6F1D85E609E2C3B7871718955C7C443 2009-12-10 16:11:13 : fleminr Users encrypted answer was retrieved from Directory. : 0x9679D5119C239348A0C56A95F7A5C458BBE8 2009-12-10 16:11:13 : fleminr Users encrypted answer was retrieved from Directory. : 0x49F5392353DC01C540CCBDB966D394E30C03 2009-12-10 16:11:20 : fleminr Retrieved password data from array : 0xC32DF6F1D85E609E2C3B7871718955C7C443 2009-12-10 16:11:20 : fleminr String was trimed left 1 characters : 0xC32DF6F1D85E609E2C3B7871718955C7C443 2009-12-10 16:11:20 : fleminr Decrypted output1 : 0x6131 2009-12-10 16:11:20 : fleminr Decrypted output2 : a1 2009-12-10 16:11:20 : fleminr Encrypted Binary Output Data : a1 yes the issue was that the function to get the value from the array caused the string to start with a white space. corrected code: Local $eArray1 = GetDirObj($userid,"question1","sn","userPassword") Local $data1 = _ArrayToString($eArray1," ",8,8) Local $data2 = StringTrimLeft ( $data1, 1) $decrypt_data1 = AES_Decrypt($userid,$data2) Anyone have any way around this issue? Link to comment Share on other sites More sharing options...
SkinnyWhiteGuy Posted December 10, 2009 Share Posted December 10, 2009 Looks like your using a Space to combine the data with _ArrayToString($eArray1, " ", 8, 8). Why not use blank, with no space? Link to comment Share on other sites More sharing options...
RogFleming Posted December 10, 2009 Share Posted December 10, 2009 Looks like your using a Space to combine the data with _ArrayToString($eArray1, " ", 8, 8). Why not use blank, with no space?I did try "" but it did not work, I guess I could try "|" Link to comment Share on other sites More sharing options...
SkinnyWhiteGuy Posted December 10, 2009 Share Posted December 10, 2009 Wait... Why are you using ArrayToString like this? I don't use the Array includes, so I didn't realize what this did until just now. Using 8, 8 on there just retrieves one element, the 8th. Why do that? Why not just use $eArray1[8]? That's the element you want, nothing else... Link to comment Share on other sites More sharing options...
RogFleming Posted December 10, 2009 Share Posted December 10, 2009 Looks like your using a Space to combine the data with _ArrayToString($eArray1, " ", 8, 8). Why not use blank, with no space?that white space is still present even with "" or "|" Link to comment Share on other sites More sharing options...
RogFleming Posted December 10, 2009 Share Posted December 10, 2009 Wait... Why are you using ArrayToString like this? I don't use the Array includes, so I didn't realize what this did until just now. Using 8, 8 on there just retrieves one element, the 8th. Why do that? Why not just use $eArray1[8]? That's the element you want, nothing else... white space still cames from array Local $data1 = $eArray1[8] Looking at the array itself it appears all elements have a space in front of them. Link to comment Share on other sites More sharing options...
wraithdu Posted December 11, 2009 Share Posted December 11, 2009 I was just gonna say...the problem is your GetDirObj() function which is returning elements with white space, not the _ArrayToString() or direct array access. Link to comment Share on other sites More sharing options...
Baraoic Posted May 16, 2010 Share Posted May 16, 2010 (edited) Sorry to revive an old post but I wanted to play around with AES encryption and I could not get this script to work. When I try doing anything it causes autoit to crash. I was just trying to do$Encrypted = _AesEncrypt("test", "test") Msgbox(0,'',$Encrypted) Edited May 16, 2010 by Onichan Link to comment Share on other sites More sharing options...
xeroTechnologiesLLC Posted February 12, 2012 Share Posted February 12, 2012 Oh man I'm so thankful I found this. This is truly amazing work. Our next project improvement was going to require encryption and decryption and, not having the confidence to even know where to begin, I'm EXTREMELY thankful you set this up for all of us. Amazing work. Well done! Link to comment Share on other sites More sharing options...
Michahe Posted March 24, 2012 Share Posted March 24, 2012 (edited) Hello to all. I use the AES-UDF from Ward for my AKryto-Tool, because my tool with the UDF also works under Win2k with AES. But when i use the funktion: _AesEncryptFile($password, $infile, $outfile, "CFB") in x64-mode (compiled at x64 or start with "AutoIt3_x64.exe"), the _AesEncryptKey()-funktion abort in line 59 ("If $Ret[0] Then") because there is no array !? It seems the AES-UDF does not work under x64-mode. Is there a chance to correct this ? Thanks to all.... Micha Here are the used UDFs and a testscript:TestAES.zip Edited March 24, 2012 by Michahe Link to comment Share on other sites More sharing options...
BrewManNH Posted March 24, 2012 Share Posted March 24, 2012 Have you tried running it in 32bit mode instead of 64? 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...
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