Modify

Opened 16 years ago

Closed 16 years ago

#1738 closed Bug (Duplicate)

crypt.au3 - Calling of _Crypt_EncryptData

Reported by: pille2009@… Owned by:
Milestone: Component: AutoIt
Version: 3.3.6.0 Severity: None
Keywords: crypt Cc:

Description

The function callings of _Crypt_EncryptData() for example in _Crypt_EncryptFile() are wrong. The last Parameter $fFinal in _Crypt_EncryptData() must only be switch to false if you are using a stream cipher like RC4.

if using a blockcipher like AES or DES, this param must always be TRUE

Attachments (0)

Change History (4)

comment:1 by anonymous, 16 years ago

this issue is the reason why crypting/decrypting of files larger than buffer (1024 * 1024) e.q. 1MB corrupts the file

comment:2 by J-Paul Mesnage, 16 years ago

the _Crypt_EncryptData() has been fixed for the next beta/Release with

Func _Crypt_EncryptData($vData, $vCryptKey, $iALG_ID, $fFinal = True)
	Local $hBuff
	Local $iError
	Local $vReturn
	Local $ReqBuffSize
	Local $aRet
	_Crypt_Startup()

	Do
		If $iALG_ID <> $CALG_USERKEY Then
			$vCryptKey = _Crypt_DeriveKey( $vCryptKey,$iALG_ID)
			If @error Then
				$iError = 1
				$vReturn = -1
				ExitLoop
			EndIf
		EndIf

		$aRet = DllCall(__Crypt_DllHandle(), "bool", "CryptEncrypt", "handle", $vCryptKey, "handle", 0, "bool", $fFinal, "dword", 0, "ptr", 0, _
				"dword*", BinaryLen($vData), "dword", 0)
		If @error Or Not $aRet[0] Then
			$iError = 2
			$vReturn = -1
			ExitLoop
		EndIf

		$ReqBuffSize = $aRet[6]
		$hBuff = DllStructCreate("byte[" & $ReqBuffSize & "]")
		DllStructSetData($hBuff, 1, $vData)
		$aRet = DllCall(__Crypt_DllHandle(), "bool", "CryptEncrypt", "handle", $vCryptKey, "handle", 0, "bool", $fFinal, "dword", 0, "ptr", DllStructGetPtr($hBuff), _
				"dword*", BinaryLen($vData), "dword", DllStructGetSize($hBuff))
		If @error Or Not $aRet[0] Then
			$iError = 3
			$vReturn = -1
			ExitLoop
		EndIf
		$iError = 0
		$vReturn = DllStructGetData($hBuff, 1)
	Until True

	If $iALG_ID <> $CALG_USERKEY Then _Crypt_DestroyKey($vCryptKey)
	_Crypt_Shutdown()
	Return SetError($iError, 0, $vReturn)
EndFunc   ;==>_Crypt_EncryptData

Does that solve your issue?

comment:3 by pille2009@…, 16 years ago

Works like a charme.

Tested on various files with a varying filesize from 10 KB up to 700 MB. Tested using RC4 and AES256. MD5-Hashsums machting.

This Bug can be closed

comment:4 by J-Paul Mesnage, 16 years ago

Resolution: Duplicate
Status: newclosed

no problem as it was already closed with a previous ticket ...

Modify Ticket

Action
as closed The ticket will remain with no owner.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.