AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

MD5, SHA1, CRC32 of the File

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Wed Sep 26, 2007 5:58 am    Post subject: MD5, SHA1, CRC32 of the File Reply with quote

It will calculate the hash MD5/SHA1/CRC32 of the files in any format.

NEED the standard library File.ahk.

DOWNLOAD Hash.ahk.
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 4511
Location: Belgrade

PostPosted: Wed Sep 26, 2007 7:18 am    Post subject: Reply with quote

Thx.

I wonder why didn't u united in the one function that takes parameter for desired hash type
_________________
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Wed Sep 26, 2007 8:45 am    Post subject: Reply with quote

majkinetor wrote:
I wonder why didn't u united in the one function that takes parameter for desired hash type

I wasn't sure if people would like it as it uses different functions for them.
I updated the script combining them into Hash(). SID = 0 for CRC32.
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 4511
Location: Belgrade

PostPosted: Wed Sep 26, 2007 8:55 am    Post subject: Reply with quote

Why not using meaningfull things instead numbers:

Code:
Hash(&sData, size, "md5")
Hash(&sData, size, "crc32")
Hash(&sData, size, "sha1")


With good interface, its nice for StdLib.

EDIT:
You can also check if first parameter is not a number. If so, you can treat it as a file name, so function becomes really practical. This introuduces dependency to File.ahk unless you paste the code, however, something which isn't true now.
_________________
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Wed Sep 26, 2007 11:19 am    Post subject: Reply with quote

majkinetor wrote:
Why not using meaningfull things instead numbers:

I preferred numbers as then can easily use other ones too like MD2, MD4, or SHA256 etc if supported.
Anyway, I added another one Hash_str.ahk to the zip which accepts (only) the string CRC32/MD5/SHA1 as SID.

Quote:
You can also check if first parameter is not a number. If so, you can treat it as a file name, so function becomes really practical. This introuduces dependency to File.ahk unless you paste the code, however, something which isn't true now.

Making Hash() accept the file path really introduces a dependency on other script/Library even if it's not used.
In the current context, you can use any other means than File_WriteMemory() to prepare the buffer of data without dependency on unused script/Library.
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4710
Location: Boulder, CO

PostPosted: Wed Sep 26, 2007 6:49 pm    Post subject: Reply with quote

Cool! Sean, if you are already in the advapi32.dll, can you figure out how to call AES properly? It should work on XP, 2003 and Vista, and could give us a fast and secure encryption.
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 4511
Location: Belgrade

PostPosted: Wed Sep 26, 2007 7:42 pm    Post subject: Reply with quote

How to do large files ?

Those that can't fit into memory, for instance 1GB movie. Acctually by default it can't be bigger then 64MB.
I wonder, if file is read in chunks in loop, how to sum up cheksums.


AES wuld be indeed very good to have.
_________________
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Thu Sep 27, 2007 12:45 am    Post subject: Reply with quote

Laszlo wrote:
Cool! Sean, if you are already in the advapi32.dll, can you figure out how to call AES properly? It should work on XP, 2003 and Vista, and could give us a fast and secure encryption.

Let me take a look at it, but I don't have prior knowledge on it so I don't know how much work it would require.
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Thu Sep 27, 2007 12:49 am    Post subject: Reply with quote

majkinetor wrote:
I wonder, if file is read in chunks in loop, how to sum up cheksums.

They support chunk of data.
It's already possible for CRC32 in its current form, but need a tweak for CryptHash... function. Can add any data anytime until CryptGetHashParam is first called.

Code:
sFile := A_AhkPath
hFile := File_CreateFile(sFile, 3, 0x80000000, 1)
sHash := 0
VarSetCapacity(sData,65535)
Loop
{
   If Not   nSize := File_ReadFile(hFile, &sData, 65536)
      Break
   sHash := Hash(&sData, nSize, 0, "0x" . sHash)
}
File_CloseHandle(hFile)

nSize := File_WriteMemory(sFile, sData1)
MsgBox, % Hash(&sData1, nSize, 0) . " : " . sHash
Back to top
View user's profile Send private message
A-BitsCode
Guest





PostPosted: Fri Jan 18, 2008 7:07 pm    Post subject: Compatibility Reply with quote

Can someone explain to me why is this function not working on Windows XP Pro while in remote desktop session? It is running fine when logged in normal mode.
Back to top
A-BitsCode
Guest





PostPosted: Fri Jan 18, 2008 7:33 pm    Post subject: Compatibility Reply with quote

When running the function inside a remote desktop session, I get this result:

[img]http://www-server.info/ahk/remote_desktop.bmp[/img]

When running the function on the same computer but inside a normal session, I get this result:

[img]http://www-server.info/ahk/normal_mode.bmp[/img]

Any help would be appreciated.
Back to top
quatermass



Joined: 14 Dec 2005
Posts: 216

PostPosted: Wed Dec 03, 2008 1:13 pm    Post subject: Sean's - MD5, SHA1, CRC32 of the File Reply with quote

Sean wrote:
It will calculate the hash MD5/SHA1/CRC32 of the files in any format.

NEED the standard library File.ahk.

DOWNLOAD Hash.ahk.


Just to point out that Hash.ahk isn't a library file and File.ahk seems to need the Crypt.ahk library file. Smile
_________________
Stuart Halliday
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group