那么我再支持一下……
#include <Crypt.au3>
Local $sFile = "D:\Code\Crypt\AES\Test.txt"
_CryptFile_ByMark($sFile)
If @error Then ConsoleWrite(@error & @TAB & @extended & @CRLF)
Func _CryptFile_ByMark($sFile, $sSave = Default, $sMark = "Crypted", $sData = 2333)
If $sSave = Default Then $sSave = $sFile
If Not FileExists($sFile) Then Return SetError(1, 0, "")
Local $sTemp = StringLeft($sFile, StringInStr($sFile, "\", 0, -1)) & "Crypt_Temp.tmp"
ConsoleWrite($sTemp & @CRLF)
Local $iSize = FileGetSize($sFile), $iSpace = Round(DriveSpaceFree(StringLeft($sFile, 3)) * 1024 ^ 2)
If $iSpace < $iSize Then Return SetError(2, $iSpace, "")
Local $hFile_Temp = FileOpen($sTemp, 2 + 16)
Local $hFile_In = FileOpen($sFile, 16)
Local $bWrite = "", $bMark = StringToBinary($sMark), $iRead = 0
Local $bTitle = FileRead($sFile, BinaryLen($bMark))
If $bTitle = $bMark Then
$iRead += BinaryLen($bMark)
FileSetPos($hFile_In, $iRead, 0)
Else
FileWrite($hFile_Temp, $bMark)
EndIf
Local $hHash = _Crypt_HashData($sData, $CALG_SHA1)
Do
$bRead = FileRead($hFile_In, 1024 ^ 2)
$iRead += BinaryLen($bRead)
If $bTitle = $bMark Then
$bWrite = _Crypt_DecryptData($bRead, $hHash, $CALG_AES_128, (($iRead >= $iSize) ? True : False))
Else
$bWrite = _Crypt_EncryptData($bRead, $hHash, $CALG_AES_128, (($iRead >= $iSize) ? True : False))
EndIf
If @error Then Return SetError(3, @error, "")
FileWrite($hFile_Temp, $bWrite)
Until $iRead >= $iSize
FileClose($hFile_In)
FileClose($hFile_Temp)
FileMove($sTemp, $sSave, 1 + 8)
EndFunc ;==>_CryptFile_ByMark
|