sharpcompress icon indicating copy to clipboard operation
sharpcompress copied to clipboard

Detect if rar file is password protected?

Open evpxregu opened this issue 8 years ago • 2 comments

Hi,

Is there any way to check if a rar or another other type is password protected? Currently I check if it throws a CryptographicException but this does not work for .rar files where the filenames are not encrypted, when I then try to open the entrystream or extract the entries I get a NullReferenceException.

Thanks!

evpxregu avatar Dec 20 '16 21:12 evpxregu

I might be doing something wrong for that case. I think the only encryption flag I check for RARs is on the ArchiveHeader.

I'd have to dig into the spec.

Could be a good PR.

adamhathcock avatar Dec 21 '16 17:12 adamhathcock

I noticed this issue and found that checking IsEncrypted on the Entry was the best method. If you're not using passwords then you should not attempt to process an Entry with IsEncrypted is True.

If the archive is encrypted with encrypted filenames then catching SharpCompresses CryptographicException when no password is set indicates it's passworded.

Nanook avatar May 04 '22 10:05 Nanook