Sign in to follow this  
Followers 0
zizou86

Data Encryption Standard (DES) on AutoIt

4 posts in this topic

Hi,

I am aware that AutoIt has no support for DES encryption and I am looking for a script that can help. I am very reluctant to code the entire DES out myself in AutoIt as that is going to take a tremendous amount of time and kind of reinvents the wheel.

I know that Windows has some form of API for DES. However, I tried a DLL call and there is the _Crypt_DeriveKey function that helps you generate a key from a short password. I cannot use this as I already have a binary/hex key and I will like to use this key for my DES encryption.

Hence, I found out that the API has CryptImportKey function. But I am extremely unsure of how to go about using it as I am not very good at Dll calls.

http://msdn.microsoft.com/en-us/library/windows/desktop/aa380207(v=VS.85).aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/aa382383(v=VS.85).aspx

Here's what I have tried (its pretty much translations of the 2nd link posted above):

$aRet = DllCall("advapi32.dll", 'int', 'CryptAcquireContext', 'ptr*', 0, 'ptr', 0, 'ptr', 0, 'dword', 1, 'dword', 0xF0000000)

Local $DesKeyBlob[20] = [0x08,0x02,0x00,0x00,0x01,0x66,0x00,0x00,0x08,0x00,0x00,0x00,0xf1,0x0e,0x25,0x7c,0x6b,0xce,0x0d,0x34]

Local $phKey= DllStructCreate("uint")

Local $phKey= DllStructCreate("uint")

Local $ret= DllCall("Advapi32.dll","int","CryptImportKey","ptr*",$hContext,"int",$DesKeyBlob,"dword",BinaryLen($DesKeyBlob),"ptr",0,"dword",1,"ptr*", DllStructGetPtr($phKey))

My codes reported no error but the key is always 0. I tried to do an exportKey after the import and once more, the key is 0. I have honestly no idea how I can fix this as I have not really used AutoIt and DLLcalls together before.

Can some kind soul please point me to the right direction please? I understand that DES is obsolette and I really should use AES. But I do really need to use DES instead of AES for this. I really appreciate if someone can show me an example of this so I can continue with my programming work for the other forms of encryption.

Thank you.

Regards.

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Sorry I seem unable to edit my codes. The codes I posted above lacked the code tags so here I am reposting here for ease of reading of my AutoIT codes:

$aRet = DllCall("advapi32.dll", 'int', 'CryptAcquireContext', 'ptr*', 0, 'ptr', 0, 'ptr', 0, 'dword', 1, 'dword', 0xF0000000)
Local $DesKeyBlob[20] = [0x08,0x02,0x00,0x00,0x01,0x66,0x00,0x00,0x08,0x00,0x00,0x00,0xf1,0x0e,0x25,0x7c,0x6b,0xce,0x0d,0x34]
 
Local $phKey= DllStructCreate("uint")
Local $phKey= DllStructCreate("uint")
Local $ret= DllCall("Advapi32.dll","int","CryptImportKey","ptr*",$hContext,"int",$DesKeyBlob,"dword",BinaryLen($DesKeyBlob),"ptr",0,"dword",1,"ptr*", DllStructGetPtr($phKey
Edited by zizou86

Share this post


Link to post
Share on other sites

If I remember rightly, there is a built in library with AutoIt: Crypt.au3. I think that calls the same functions as above (it was definitely advapi anyway) so it might do what you want.

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
Sign in to follow this  
Followers 0