AutoHotkey Community

It is currently May 26th, 2012, 8:33 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: November 6th, 2008, 3:55 pm 
Offline

Joined: August 20th, 2008, 4:25 pm
Posts: 256
http://www.autohotkey.com/forum/viewtopic.php?t=23719

^ I refer to this post up here. I understand the use of functions, but this doesn't make sense to me. Can anyone clear this up for me?

_________________
-Chavez.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 6th, 2008, 9:40 pm 
Sorry I'm a complete idiot when it comes to complex things like this, nevertheless I'd recommend to get in touch (PM) Sean and/or Laszlo (or whomever has outed him-/herself as an de-/encryption geek)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2008, 12:22 pm 
Offline

Joined: August 20th, 2008, 4:25 pm
Posts: 256
BoBo² wrote:
Sorry I'm a complete idiot when it comes to complex things like this, nevertheless I'd recommend to get in touch (PM) Sean and/or Laszlo (or whomever has outed him-/herself as an de-/encryption geek)


Sean hasn't answered yet. I'll try Laszlo.

_________________
-Chavez.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 7th, 2008, 6:03 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
You can use Sean's Crypt_AES function on data in memory this way (XP or Vista):
Code:
Password = AutoHotkey
Data = 12345678901234567
Len := StrLen(Data)
Buffer = %Data%0123456789abcdef ; allocate 16 byte more space

size := Crypt_AES(&Buffer, Len, Password, 256, 1)
MsgBox % "Plaintext size = " Len "`nCiphertext size = " size "`nCiphertext: " SubStr(Buffer,1,size)

size := Crypt_AES(&Buffer, size, Password, 256, 0)
MsgBox % "`Plaintext size = " size "`nPlaintext: " SubStr(Buffer,1,size)

Crypt_AES(pData, nSize, sPassword, SID = 256, bEncrypt = True) {
   CALG_AES_256 := 1 + CALG_AES_192 := 1 + CALG_AES_128 := 0x660E
   CALG_SHA1 := 1 + CALG_MD5 := 0x8003
   DllCall("advapi32\CryptAcquireContextA", "UintP", hProv, "Uint", 0, "str"
   , "Microsoft Enhanced RSA and AES Cryptographic Provider" . (A_OSVersion="WIN_XP" ? " (Prototype)" : ""), "Uint", 24, "Uint", 0)
   DllCall("advapi32\CryptCreateHash", "Uint", hProv, "Uint", CALG_SHA1, "Uint", 0, "Uint", 0, "UintP", hHash)
   DllCall("advapi32\CryptHashData", "Uint", hHash, "Uint", &sPassword, "Uint", StrLen(sPassword), "Uint", 0)
   DllCall("advapi32\CryptDeriveKey", "Uint", hProv, "Uint", CALG_AES_%SID%, "Uint", hHash, "Uint", SID<<16, "UintP", hKey)
   DllCall("advapi32\CryptDestroyHash", "Uint", hHash)
   If bEncrypt
      DllCall("advapi32\CryptEncrypt", "Uint", hKey, "Uint", 0, "Uint", True, "Uint", 0, "Uint", pData, "UintP", nSize, "Uint", nSize+16)
   Else  DllCall("advapi32\CryptDecrypt", "Uint", hKey, "Uint", 0, "Uint", True, "Uint", 0, "Uint", pData, "UintP", nSize)
   DllCall("advapi32\CryptDestroyKey", "Uint", hKey)
   DllCall("advapi32\CryptReleaseContext", "Uint", hProv, "Uint", 0)
   Return   nSize
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2009, 11:17 am 
Offline

Joined: August 8th, 2009, 10:10 pm
Posts: 17
How to decrypt encrypted data only?

i.e. If I encrypt a string, 123456, and the encrypted string is 2aosi231, how to decrypt encrypted string later?

I wonder if that script encrypt and decrypt a string sequentially, but I think that is a little useless. I can't believe this, so I'm asking for help.

I want to encrypt a password on an ini file, and later retrieve it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2009, 4:59 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Set the last parameter of Crypt_AES to 0. Be careful, the encrypted data can contain \0, so string functions might not work with it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2009, 8:52 pm 
Offline

Joined: August 8th, 2009, 10:10 pm
Posts: 17
Laszlo wrote:
Set the last parameter of Crypt_AES to 0.


thanks lazlo but I knew that...

i.e.:

Code:
Password = AutoHotkey
Data = 2aosi231 ; encrypted data before with the same password
Len := StrLen(Data)
Buffer = %Data%0123456789abcdef ; allocate 16 byte more space

size := Crypt_AES(&Buffer, size, Password, 256, 0)
MsgBox % "`Plaintext size = " size "`nPlaintext: " SubStr(Buffer,1,size)


Size parameter isn't specified... I tried StrLen of data or buffer as size parameter, but it doesn't work, blank string.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2009, 9:47 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
You got the size parameter when the original data was encrypted. You have to use that.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2009, 9:51 pm 
Offline

Joined: August 8th, 2009, 10:10 pm
Posts: 17
Laszlo wrote:
You got the size parameter when the original data was encrypted. You have to use that.


This means that I have to store the original size too...?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 21st, 2009, 10:33 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
You have to save the size of the encrypted data, not the size of the data, and use it at decryption.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 22nd, 2009, 3:00 pm 
Offline

Joined: August 8th, 2009, 10:10 pm
Posts: 17
Ehr... the second parameter variable "size" on this

Code:
Crypt_AES(&Buffer, size, Password, 256, 0)


is the encrypted string, isn't it?

If so, what to set in "Buffer"?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 22nd, 2009, 3:15 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Buffer contains the encrypted binary data, the actual size used in bytes is contained in the variable "size". It is not always the same as the length of the input (the length of cleartext), or the allocated memory for Buffer.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 22nd, 2009, 3:26 pm 
Offline

Joined: August 8th, 2009, 10:10 pm
Posts: 17
Laszlo wrote:
Buffer contains the encrypted binary data, the actual size used in bytes is contained in the variable "size". It is not always the same as the length of the input (the length of cleartext), or the allocated memory for Buffer.


Okay now I understood. Thank you Laszlo :)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, joetazz, Mickers, Pulover, tidbit, tomoe_uehara and 55 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group