在java中读取.msg文件的加密附件

时间:2015-07-31 11:31:39

标签: java apache-poi msg

我有很多带有加密附件的.msg文件。我目前使用的是apache poi库。目前,我的代码提供了.docx,.xls,.xlsx文件的路径,我可以拥有解密的内容。问题是我想要解密msg文件的附件。

public static void decryptMSG(String path,String[] password) throws IOException {
    MAPIMessage msg = new MAPIMessage(path);
    AttachmentChunks attachments[] = msg.getAttachmentFiles();
    if(attachments.length > 0) {
        for (AttachmentChunks a  : attachments) {
            String attachname=a.attachLongFileName.toString();
            ByteArrayInputStream fileIn = new ByteArrayInputStream(a.attachData.getValue());
            File f = new File(path+"_decrypted"+ a.attachLongFileName.toString()); // output
            OutputStream fileOut = null;
            try {
                fileOut = new FileOutputStream(f);
                byte[] buffer = new byte[2048];
                int bNum = fileIn.read(buffer);
                while(bNum > 0) {
                    fileOut.write(buffer);
                    bNum = fileIn.read(buffer);
                }   
            }
            finally{
                   .....
            }

这是读取未加密的.msg附件的正常代码。

Q1:请告诉我在哪里可以设置密码?

Q2:如果库不支持设置密码,是否可以将AttachmentChunks复制到路径?我的意思是给每个Attachmentchunk一个存储Attachemntchunk的物理路径?

问题3:或者如果您知道java或python中的任何lib可以解决解密.msg文件,请告诉我。谢谢,

1 个答案:

答案 0 :(得分:1)

您需要创建EncryptionKey / EncryptionInfo(取决于加密方法)。有关更深入的解释,请参阅this page

相关问题