I have an ADF that generates files and then Zips them to a container. After that's completed, I call an Azure Function that reads the Zip file and adds passwords. From the documentation, the password is applied to the individual entries in the archive. I iterate through the entries in the Azure Function and add the passwords and then upload that zip file back to the same container OVERWRITING the orginal one. However, when I unzip the file (using 7zip) the passwords I added doesn't work and says it's wrong.
Here's the block of code:
string zipName = objParam.ZipFileName;
Logger.LogInformation("Starting Password Protect of Zip File");
var blobClient = BlobServiceClient.GetBlobContainerClient(objParam.DestinationContainer).GetBlobClient(zipName);
Logger.LogInformation("Zip File Name: " + objParam.ZipFileName)
using (Stream zipStream = await blobClient.OpenReadAsync().ConfigureAwait(false))
{
ZipFile zipFile = ZipFile.Read(zipStream);
zipFile.Encryption = EncryptionAlgorithm.None;
zipFile.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
foreach (var entry in zipFile)
{
entry.Password = "Test123";
}
var zipOutputStream = new MemoryStream();
zipFile.Save(zipOutputStream);
zipOutputStream.Seek(0, SeekOrigin.Begin);
zipStream.Close();
await blobClient.UploadAsync(zipOutputStream, true);
zipOutputStream.Close();
}
Password protect a zip file using DotNetZip library.
I modified the code a bit and it worked for me.
And installed the below NuGets.
Uploaded to azure.
using code able to encrypt the files.
After download prompting for the password to open the file.