Hi,
I have a 7z archive with one file that is encrypted. When I extract the file using an incorrect password, the extraction completes without error. The extracted content is of course wrong as the password was wrong.
Is there a way that Aspose.Zip can tell that the password was incorrect, so I can stop processing at that point?
Hello @benarnold, it is strange you have not got InvalidDataException
. What compression method uses that archive? You can also attach it here for us to review.
Hi Eugene,
Here is a small example that shows it. Hopefully you can show me what I’m doing wrong
using Aspose.Zip.Saving;
using Aspose.Zip.SevenZip;
using System.Text;
var archive = new SevenZipArchive(new SevenZipEntrySettings(
new SevenZipStoreCompressionSettings(),
new SevenZipAESEncryptionSettings("PASSWORD")));
archive.CreateEntry("example.text", new MemoryStream(Encoding.UTF8.GetBytes("hello")));
var archiveStream = new MemoryStream();
archive.Save(archiveStream);
archiveStream.Position = 0;
var unarchive = new SevenZipArchive(archiveStream);
var unarchiveStream = new MemoryStream();
unarchive.Entries[0].Extract(unarchiveStream, "the-wrong-password");
Console.WriteLine(Encoding.UTF8.GetString(unarchiveStream.ToArray()));
Oh, you are using store (no compression) method. Lacking exception here is a bug. We opened a ticket ZIPNET-1017 for this. We’ll notify you when it fixed, most likely in March version.
Version 23.5 raises exception on extraction with wrong password.
Thanks Eugene, I’ll try it out
BTW, SevenZipArchive
is IDisposable
, so please wrap it with using
statement.