Completed
Last Updated: 15 May 2024 06:27 by ADMIN
Release 2024.2.426 (2024 Q2)
XicoFininho
Created on: 15 Mar 2024 15:42
Category: ZipLibrary
Type: Bug Report
1
ZipLibrary: Can't open newly added file to a password protected zip archive

The attached gif file illustrates the inability to open the newly added file with the password: 

Sub Main()
	Dim sZipFilePath As String = "..\..\test.zip"
	File.Delete(sZipFilePath)

	CreateArchive(sZipFilePath)
	Dim decryptionSettings As DecryptionSettings = EncryptionSettings.CreateDecryptionSettings()
	AddHandler decryptionSettings.PasswordRequired, AddressOf DecryptionSettings_PasswordRequired
	Dim compressionSettings As CompressionSettings = Nothing
	Dim encoding As Encoding = Nothing
	Using oFS As FileStream = File.Open(sZipFilePath, FileMode.OpenOrCreate)


		Using oArchive As ZipArchive = ZipArchive.Update(oFS, encoding, compressionSettings, decryptionSettings)
			Using entry As ZipArchiveEntry = oArchive.CreateEntry("newText.txt")
				Dim writer As StreamWriter = New StreamWriter(entry.Open())
				writer.WriteLine("Hello world!")
				writer.Flush()
			End Using
		End Using
	End Using
End Sub

Private Sub CreateArchive(sZipFilePath As String)
	Using stream As Stream = File.Open(sZipFilePath, FileMode.Create)
		Dim _encryptionSettings As PasswordEncryptionSettings = EncryptionSettings.CreatePkzipPasswordEncryptionSettings()
		_encryptionSettings.Password = "telerik"
		Dim compressionSettings As CompressionSettings = Nothing
		Dim encoding As Encoding = Nothing

		Using archive As ZipArchive = ZipArchive.Create(stream, encoding, compressionSettings, _encryptionSettings)

			Using entry As ZipArchiveEntry = archive.CreateEntry("text.txt")
				Dim writer As StreamWriter = New StreamWriter(entry.Open())
				writer.WriteLine("Hello world!")
				writer.Flush()
			End Using
		End Using
	End Using
End Sub

Private Sub DecryptionSettings_PasswordRequired(ByVal sender As Object, ByVal e As PasswordRequiredEventArgs)
	e.Password = "telerik"
End Sub

 

Workaround: Until this bug is fixed the obsolete API could be used instead: 

ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Create, true, encoding, compressionSettings, encryptionSettings)
and
ZipArchive oArchive = new ZipArchive(stream, ZipArchiveMode.Update, true, encoding, compressionSettings, decryptionSettings)

0 comments