javascriptsecuritypassword-protectionpdf.jsdrm

How do I hide a password stored in a javascript file to open a PDF file with PDF.JS?


I'm developping a web app which basically opens a pdf file using pdf.js. The pdf file is protected with a password. Here's an extract of the code.

    var the_password = 'thepassword';
    var pdf = 'document.pdf';
    var loading = pdfjsLib.getDocument({ url: pdf, password: the_password });

So on the client side everyone can see my password, and I don't want that as my aim is that no one can use the pdf file outside the web app.

How can I protect the password ?

Thanking you in advance.


Solution

  • Thanks everyone for your answer.

    Indeed as most of you said, there are no real solution to my problem. But having a password in plain text at the beginning of a javascript file was something I thought everybody would figure out.

    So here's what I did :

    1. Create a php file with my password in it
    <?php echo 'password' ?>
    
    1. Then, when I need it to load my pdf file with pdf.js, I do an Ajax request
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) 
        {
            loading = pdfjsLib.getDocument({ url: pdf_url, password: this.responseText 
        }
    );
    xmlhttp.open("GET", "filewithpassword.php", true);
    xmlhttp.send();
    

    Still, there's an easy way to find the password, but it's still better than the plain text, and I'll stick with this.

    Thanks everyone for your help.