I have a class wrapper for working with the Telerik zip library. Since I updated my project to work with a new version (Q2) there started a problem with zip files. I can create a zip file protected with some password, but I cannot read or update it, may some problem is with decryption operation, which also occurs in default Windows Explorer and 7Zip application.
There's a code that I use for the wrapper:
public void Create(string archivePath, string? password = null)
{
using var baseStream = fileSystem.FileStream.New(archivePath, FileMode.Create, FileAccess.ReadWrite);
using var archive = ZipArchive.Create(baseStream, null, compressionSettings, GetEncryptionSettings(password));
}
public void SerializeEntry<T>(string archivePath, string entryName, T entry, string? password = null)
{
using var baseStream = fileSystem.FileStream.New(archivePath, FileMode.Open, FileAccess.ReadWrite);
using var archive = ZipArchive.Update(baseStream, null, compressionSettings, GetDecryptionSettings(password));
archive.GetEntry(entryName)?.Delete();
XmlInOut<T>.SaveToStream(archive.CreateEntry(entryName).Open(), entry);
}
public T DeserializeEntry<T>(string archivePath, string entryName, string? password = null)
{
using var baseStream = fileSystem.FileStream.New(archivePath, FileMode.Open, FileAccess.ReadWrite);
using var archive = ZipArchive.Read(baseStream, null, compressionSettings, GetDecryptionSettings(password));
return XmlInOut<T>.LoadFromStream(archive.GetEntry(entryName).Open());
}
{
var result = EncryptionSettings.CreateAesPasswordEncryptionSettings();
result.Password = password;
return result;
}
private DecryptionSettings GetDecryptionSettings(string? password)
{
var result = DecryptionSettings.CreateDecryptionSettings();
result.PasswordRequired += (s, a) => a.Password = password;
return result;
}
Hello Kostiantyn,
I noticed that you have opened a separate private support ticket (1661312) regarding this issue you are experiencing. Because of the nature of this case, this thread being public, and the potential sharing of resources, I suggest we continue our conversation in the other thread in order to take advantage of its privacy.
That said, if you decide there is anything worth mentioning here for public access, feel free to add your feedback.
Regards,
Yoan