I’m working on an in-browser PGP Decrypter.
OpenPGPJS work’s perfectly when decrypting messages and txt files but I can’t figure it out why it won’t work with excel xlsx files.
When I decrypt the file content I get a broken file in output.
for (let enAtt of encryptedAttachments) {
if (enAtt.encryptedAttachment.includes('-----BEGIN PGP PUBLIC KEY BLOCK-----')) continue;
const attachmentContent = await readMessage({
armoredMessage: enAtt.encryptedAttachment // parse armored message
});
const { data: decryptedAtt, signatures } = await decrypt({
message: attachmentContent,
verificationKeys: publicKey, // optional
decryptionKeys: privateKey
});
setAttachmentButton(bodyMessageElement, enAtt.download_url, enAtt.fileName, (decryptedAtt as Data))
}
where setAttachmentButton is:
function setAttachmentButton(bodyMessageElement: HTMLDivElement, download_url: string, fileName: string, decryptedFile: Data) {
const att = bodyMessageElement.querySelector(`span[download_url="${download_url}"]`) as HTMLDivElement|null;
const button = document.createElement('button');
button.innerText = "Download Decrypted Attachment";
const mimeType = 'application/octet-stream';
const blob = new Blob([typeof decryptedFile === 'string' ? str2ab(decryptedFile) : decryptedFile], {type: mimeType});
// file.objectURL = window.URL.createObjectURL(blob);
// button.setAttribute("href", 'data:text/plain;charset=utf-8,' + encodeURIComponent(decryptedFile));
button.setAttribute("href", window.URL.createObjectURL(blob));
button.setAttribute('download', fileName);
att?.appendChild(button);
}