Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[AHK_L] Crypt - ahk cryptography class (Encryption, Hashing)


  • Please log in to reply
83 replies to this topic
AmourSpirit
  • Members
  • 93 posts
  • Last active: Mar 01 2016 04:28 PM
  • Joined: 01 Dec 2010
I Have the same Issue here. I just Downloaded the latest version to be sure and rebooted after install. Same issue

I must really be missing something up here...


No, I'm pretty sure you just downloaded the latest version of AHK_L, in which the var prefix is no longer allowed inside of classes:

[color=red]var[/color] StrEncoding := "UTF-16"

I believe if you change those instances from var to static it should work fine.



AmourSpirit
  • Members
  • 93 posts
  • Last active: Mar 01 2016 04:28 PM
  • Joined: 01 Dec 2010
Changed line 146 static StrEncoding := "UTF-16"
Changed line 147 static PassEncoding := "UTF-16"
Changed line 415 static StrEncoding := "CP0"
Changed line 416 static PassEncoding := "UTF-16"

It works for me now. Win 7 x64

I must really be missing something up here...


No, I'm pretty sure you just downloaded the latest version of AHK_L, in which the var prefix is no longer allowed inside of classes:

[color=red]var[/color] StrEncoding := "UTF-16"

I believe if you change those instances from var to static it should work fine.



Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
hello, guys, i've updated the source and fixed the problem with old "var" definition and bad password len calculating

JMeneses
  • Members
  • 161 posts
  • Last active: Oct 30 2015 02:10 PM
  • Joined: 17 Feb 2011
Sorry for my English. I think the method "StrDecryptToFile" has a file delete crypt.temp early because it gives me error opening the site have changed and it works


FileDelete,% temp_file
if !bytes := this._Encrypt( p, pp, password, 0, temp_file, ..... )
return ""

Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
JMeneses
yep, you right, it was a bug there
i have uploaded a fixed version

thank you!

  • Guests
  • Last active:
  • Joined: --
Hi Deo,

Is it Okey to use this library for my apps? Is there a license that restricts certain things?

Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
Hi
You may use/change this lib as you wish without any restrictions

  • Guests
  • Last active:
  • Joined: --
Wao, thank you so much, Deo. Bless you. :)

  • Guests
  • Last active:
  • Joined: --
Hi Deo,

Is it possible to decrypt binary data loaded in memory? I mean something like this,
Data := "Hello World!"
FileAppend, % Data, %A_ScriptDir%\tmp.txt, UTF-8
Crypt.Encrypt.FileEncrypt( A_ScriptDir "\tmp.txt", A_ScriptDir "\sample.dat", "mypassword", 7, 6)
FileDelete, %A_ScriptDir%\tmp.txt

; assuming the above has been done somewhere 
FileRead, Hash, *c %A_ScriptDir%\sample.dat
msgbox %  Crypt.Encrypt.StrDecrypt(Hash, "mypassword", 7, 6)
Actually, I'm looking for a way to decrypt text from resource in a compiled script. The text is stored in the executable and is possible to load into memory. I need to decrypt the loaded data. In order to do it, I'd like to know whether the above task is possible with your library. Thanks.

Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
Hi,
sure, here is how you can do this:
;read file's data into memory buffer
f := fileOpen( "sample.dat", "r", "CP0" )
bufSize := f.RawRead( buffer, f.Length )
f.close()
;-------First Method
Crypt.Encrypt.StrEncoding := "UTF-8" ;specify a needed encoding here, "UTF-16" is by default
;get hashed string of data since StrDecrypt use it as first parameter
hashedData := ByteToHash(buffer,bufSize)
msgbox % Crypt.Encrypt.StrDecrypt( hashedData, "mypassword", 7, 6)

;-------Second Method, a bit faster than first
if Crypt.Encrypt._Encrypt( buffer, bufSize, "mypassword", 0,0,0,7,6)
	msgbox % strget(&buffer,"UTF-8") ;specify a needed encoding here


  • Guests
  • Last active:
  • Joined: --
Hi Deo,

I get EOT characters at the end of the result string. Could you check if it happens in your environment? I'm using Unicode x86 and the script is saved as UTF-8.
Data := "Hello World!"
FileAppend, % Data, %A_ScriptDir%\tmp.txt, UTF-8
Crypt.Encrypt.FileEncrypt( A_ScriptDir "\tmp.txt", A_ScriptDir "\sample.dat", "mypassword", 7, 6)
FileDelete, %A_ScriptDir%\tmp.txt
; assuming the above has been done somewhere 

;read file's data into memory buffer
f := fileOpen( A_ScriptDir "\sample.dat", "r", "CP0" )
bufSize := f.RawRead( buffer, f.Length )
f.close()

;-------First Method
Crypt.Encrypt.StrEncoding := "UTF-8" ;specify a needed encoding here, "UTF-16" is by default
;get hashed string of data since StrDecrypt use it as first parameter
hashedData := ByteToHash(buffer,bufSize)
msgbox % Crypt.Encrypt.StrDecrypt( hashedData, "mypassword", 7, 6)

Hello World!



Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
hi
there was bug in StrDecrypt related to inproper string len calculation. I fixed it and upload new version, take it and try again.
and thanks that you found it! ;)
also, the second method should look like this now (if you'll prefer it ):
encoding = "UTF-8" ;specify a needed encoding here
if sLen := Crypt.Encrypt._Encrypt( buffer,bufSize, "mypassword", 0,0,0,7,6 )
{
  if ( encoding  = "utf-16" || encoding = "cp1200" )
    sLen /= 2
  msgbox % strget(&buffer,sLen,encoding )
}


  • Guests
  • Last active:
  • Joined: --
Hi Deo,

Glad to know the bug has been fixed. The first method works perfectly. I get a blank message box though with the second revised method. Am I using it correctly?
Data := "Hello World!"
FileAppend, % Data, %A_ScriptDir%\tmp.txt, UTF-8
Crypt.Encrypt.FileEncrypt( A_ScriptDir "\tmp.txt", A_ScriptDir "\sample.dat", "mypassword", 7, 6)
FileDelete, %A_ScriptDir%\tmp.txt
; assuming the above has been done somewhere 

;read file's data into memory buffer
f := fileOpen( A_ScriptDir "\sample.dat", "r", "CP0" )
bufSize := f.RawRead( buffer, f.Length )
f.close()

encoding = "UTF-8" ;specify a needed encoding here
if sLen := Crypt.Encrypt._Encrypt( buffer,bufSize, "mypassword", 0,0,0,7,6 )
{
  if ( encoding  = "utf-16" || encoding = "cp1200" )
    sLen /= 2
  msgbox % strget(&buffer,sLen,encoding )
}


Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
my mistake, i didn't test it
change
encoding = "UTF-8"
to
encoding := "UTF-8"


  • Guests
  • Last active:
  • Joined: --
Oh, I also didn't notice it. Thanks. It works now.