Search the Community
Showing results for tags 'cryptencrypt'.
-
Hello All, I have the following issue with using the _Crypt_EncryptData autoit function which I understand is merely a wrapper around the advapi dll's CryptEncrypt function. Part of the functionality of my script is to read a file in chunks(I cannot avoid that) encrypt the data and write it into a separate file on the disk. To read and write I use the _WinAPI_ReadFile and _WinAPI_WriteFile function. The buffer size usually is 1MB. Sometimes it's smaller, but never more than that. In order to verify the integrity of the resulting file I decrypt it with the sample script in the help for the _Crypt_DecryptFile function. I'm using a hex editor to compare the source and target files. For the most part they are the same, but It looks like there are discrepancies always with a size of 16 bytes in the files. For example: the original will be F0 FF FF FF 48 2F 0F 00 C0 2F 0F 00 00 00 00 00 68 62 69 6E 00 10 0F 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 the decrypted will be F0 FF FF FF 48 2F 0F 00 C0 2F 0F 00 00 00 00 00 2C 34 F4 B2 D7 2C 9C 62 DF 54 3C 50 63 04 52 79 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 The code I'm using is below. What am I doing wrong? Please help. I think I've tried almost everything and I still can't figure out what is causing this.I've read that the CryptEncrypt win32 api function is not thread safe, but my script isn't multithreaded. Is it possible that it's feeding in the write buffer with data taken from somewhere else _WinAPI_ReadFile($hFile, DllStructGetPtr($readbuffer), DllStructGetSize($readbuffer), $nBytes) if $final Then $varEncrypted = _Crypt_EncryptData(DllStructGetData($readbuffer, 1), "pass", $CALG_AES_128, True) $writebuffer = DllStructCreate("byte["& BinaryLen($varEncrypted) &"]") DllStructSetData($writebuffer, 1, $varEncrypted) _WinAPI_WriteFile($targetFile, DllStructGetPtr($writebuffer), DllStructGetSize($writebuffer), $nBytes) else $varEncrypted = _Crypt_EncryptData(DllStructGetData($readbuffer, 1), "pass", $CALG_AES_128, False) $writebuffer = DllStructCreate("byte["& BinaryLen($varEncrypted) &"]") DllStructSetData(writebuffer, 1, $varEncrypted) _WinAPI_WriteFile($targetFile, DllStructGetPtr($writebuffer), DllStructGetSize($writebuffer), $nBytes) endif