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

こ雲淡風輕ζ 提交于 2019-12-01 08:44:54

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!