Modify

Opened 14 years ago

Closed 14 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 Changed 14 years ago by anonymous

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

comment:2 Changed 14 years ago by Jpm

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 Changed 14 years ago by pille2009@…

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 Changed 14 years ago by Jpm

  • Resolution set to Duplicate
  • Status changed from new to closed

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

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.