DEV Community

Alexandr
Alexandr

Posted on

3 1 1

When Files Ask for a Password: A Developer's Solution

In my online world, everything was simple—a login and password were all it took: familiar, secure, and convenient.

The Challenge

Then I stumbled upon a parallel reality: password-protected files like PDF, DOC, ZIP, and more. This wasn’t a rare glitch but a widespread practice in some industries, reminiscent of the floppy disk era. My program, built for modern interactions, would freeze at the sight of such files, bluntly declaring:

"Sorry, we don’t work with these things."

I wasn’t willing to accept this limitation or force users to change long-standing habits. The solution was clear: empower the system to handle these files.

The Journey

PDFs:

I began with PDFs—the cornerstone of document workflows. After testing several PHP libraries from GitHub, which worked until confronted with “quirky” PDFs (errant line breaks or documents that cheekily included /encrypt twice), I discovered qpdf. This external tool reliably handled even the most exotic PDFs.

Office Files:

With .DOCX files, the process was relatively smooth. But the venerable .DOC? Some companies cling to it like a cherished relic, and PHP libraries for this format are scarce. Eventually, msoffcrypto-tool proved to be a true lifesaver.

Archives:

Since I was already integrating external programs via Symfony/Process, I turned to the time-tested 7-Zip for handling archives.

Introducing Lumos

Thus was born Lumos—a cohesive library combining all these tools to effortlessly handle password-protected files. The project is available on GitHub. I’m not expecting accolades or pull requests; I just hope it makes another developer’s life a little easier.


Have you ever encountered password-protected files?

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (2)

Collapse
 
xwero profile image
david duymelinck

I haven't encountered password protected documents that needed to be processed.
But I like the legwork you did!

Collapse
 
tabuna profile image
Alexandr

Thanks! I hadn’t encountered this before either, but it turns out that in many cases, it's a legal or regulatory requirement.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay