Detect if rar file is password protected? #151

Open
opened 2026-01-29 22:07:25 +00:00 by claunia · 2 comments
Owner

Originally created by @evpxregu on GitHub (Dec 20, 2016).

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!

Originally created by @evpxregu on GitHub (Dec 20, 2016). 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!
Author
Owner

@adamhathcock commented on GitHub (Dec 21, 2016):

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 commented on GitHub (Dec 21, 2016): 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.
Author
Owner

@Nanook commented on GitHub (May 4, 2022):

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 commented on GitHub (May 4, 2022): 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#151