|
Post by Christoph on Dec 22, 2003 15:21:40 GMT -5
Hi, I have a filelist in a special grid. Now I want delete these rows, if the password in the zip archive file is not correct.
I use this code:
zip1.ClearZip;
for z := grid.rowcount-1 downto 0 do begin zip1.ZipName := Grid.Cells[1,z]; zip1.Password :='32gh197asm'; Zip1.ReadZip;
if (zip1.Password <> '32gh197asm') then grid.RemoveRows(z,1); end; end;
How can I check a zip file for the the correct password? I do know the password.
Do you have an idea?
Best regards Christoph
|
|
|
Post by Kevin on Dec 22, 2003 18:14:24 GMT -5
The actual password is not stored in a zip file. Infact, there is not one password for a zip file, each file can be encrypted with a different password. The only way to be SURE that a password is correct is to use it to attempt to unzip the file. You should have the OnBadPassword event defined which will be called in the event of a bad password. One thing you can do is set the password and then call FileIsOK for one of the files. If the password is incorrect, OnBadPassword will be called. Another possibility is to do something like the following, but, it is possible for many passwords to match the decrypt header, so as I said you don't know for sure until you actually unzip the file: function CouldBePassword(Pwd: String; Index: Integer); var dh: DecryptHeaderType; CRCHighByte: BYTE; begin dh := VCLUnZip1.DecryptHeader[FileList.ItemIndex]; CRCHighByte := HIBYTE(HIWORD( VCLUnZip1.CRC[Index)); Result := DecryptByte = CRCHighByte; end;
Pwd is ofcourse your password and Index is the Index of the file you are testing.
|
|