如何用AU3验证一个文件的SHA1和CRC32?
本帖最后由 Windows8 于 2012-3-19 13:25 编辑如题,如果用
_SHA1("C:\1.TXT")
_CRC32("C:\1.TXT")
或_SHA1(FILEREAD("C:\1.TXT"))
_CRC32(FILEREAD("C:\1.TXT"))检测出来的校验值是0x多少多少的,与HASH检验的完全不同。
请问版主,如何用AU3实现HASH的这些功能呢? 我也想知道,谢谢楼主 帮助文档里有
#include "ACN_HASH.au3"
Local $msgstr = "notepad2.exe" & @CRLF
$msgstr &= "Md5:" & Check_Md5(@ScriptDir & "\notepad2.exe") & @CRLF
$msgstr &= "Sha1:" & Check_Sha1(@ScriptDir & "\notepad2.exe") & @CRLF
$msgstr &= "Crc32:" & Check_Crc32(@ScriptDir & "\notepad2.exe")
MsgBox(0, "", $msgstr)
Func Check_Md5($FileName)
Local $BufferSize = 0x20000
Local $FileHandle = FileOpen($Filename, 16)
Local $MD5CTX = _MD5Init()
Local $i
For $i = 1 To Ceiling(FileGetSize($FileName) / $BufferSize)
_MD5Input($MD5CTX, FileRead($FileHandle, $BufferSize))
Next
Local $Hash = _MD5Result($MD5CTX)
FileClose($FileHandle)
Return $Hash
EndFunc
Func Check_Sha1($FileName)
Local $BufferSize = 0x20000
Local $FileHandle = FileOpen($FileName, 16)
Local $SHA1CTX = _SHA1Init()
Local $i
For $i = 1 To Ceiling(FileGetSize($FileName) / $BufferSize)
_SHA1Input($SHA1CTX, FileRead($FileHandle, $BufferSize))
Next
Local $Hash = _SHA1Result($SHA1CTX)
FileClose($FileHandle)
Return $Hash
EndFunc
Func Check_Crc32($FileName)
Local $BufferSize = 0x20000
Local $FileHandle = FileOpen($Filename, 16)
Local $CRC32 = 0
Local $i
For $i = 1 To Ceiling(FileGetSize($Filename) / $BufferSize)
$CRC32 = _CRC32(FileRead($FileHandle, $BufferSize), BitNot($CRC32))
Next
FileClose($FileHandle)
Return Hex($CRC32, 8)
EndFunc
页:
[1]