How can i encrypt and decrypt a pdf blob with forge and store in localStorage?

前端 未结 1 1556
醉酒成梦
醉酒成梦 2021-01-14 17:16

I\'ve trying to encrypt a Blob of pdf file and store it in the localStorage and read and decrypt it later when i\'m offline.

My app is written in AngularJS and the e

相关标签:
1条回答
  • 2021-01-14 18:13

    Your decryptPDF function is returning a binary-encoded string, which is the native format forge v0.6.x works with. To convert that back to a Uint8Array do this instead:

    decipher.finish();
    return s2a(decipher.output.getBytes());
    
    function s2a(str) {
        var view = new Uint8Array(str.length);
        for (var i = 0, j = str.length; i < j; i++) {
            view[i] = str.charCodeAt(i);
        }
        return view;
    }
    

    You should also check the return value of decipher.finish() to ensure it is true. Otherwise, the decryption may have failed.

    0 讨论(0)
提交回复
热议问题