c# - Check password on a pdf file without opening -


i'm trying make brute force attack method find password on pdf files. use method check password using itextsharp

public static bool ispasswordvalid(string pdffullname, byte[] password) {     try {         pdfreader pdfreader = new pdfreader(pdffullname, password);         return true;     } catch (badpasswordexception) {         return false;     } } 

it works. take long time when pdf file size large. there way check password without loading file memory?.

a couple of things.

first, in blog post here found using constructor overload takes randomaccessfileorarray fastest. tested again source code i've got sitting around (5.5.6.0) , still twice fast string-based path method (for large files). however, constructor overload marked obsolete , might in fact removed in more recent versions you'll need deal/live that.

pdfreader pdfreader = new pdfreader(new randomaccessfileorarray(pdffullname, true), password); 

to clear, overload removed reason might want consider not using it.

second, question is there way check password without loading file memory? misleading. if memory bottleneck you'd have bigger problems. did quick test using system.io.file.readallbytes() on 80mb file , took 90 milliseconds load memory , computer 7 years old.

the actual speed problem itext needs find trailer of pdf has pointer /encrypt dictionary. because itext intended used do pdf doesn't spend whole lot of time optimizing path because going have happen no matter what. if really, care speed i'd start. i'd recommend checking out adobe's spec see how standard pdf encryption works, it's relatively simple. there's great simplified description here.

if goal cracking should able write crude password guesser looks trailer, looks , find /encrypt key , process /o , /u keys. there's lots of "gotchas" in if haven't read spec, instance documents can have multiple trailer entries, there's alternatives passwords, etc. should 99% of common pdfs out there.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -