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

标签 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 附件的正常代码。

问题1:请问可以告诉我在哪里可以设置密码吗?

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

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

最佳答案

您需要创建一个EncryptionKey/EncryptionInfo(取决于加密方法)。请参阅this page以获得更深入的解释。

关于java - 在java中读取.msg文件的加密附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31745139/

相关文章:

java - 为什么不能将 Java 包命名为 "default"?

java - 在JAVA中向列表中的每个对象添加完整的对象列表

css - ".msg"字体颜色在 Mac 和 Windows 上不同

powershell - 使用Powershell重命名.msg文件

java - 使用 Streams 将嵌套整数列表转换为二维数组 ( List<List<Integer>> -> int[][] )

java - 区别只是 List 和 List<Object> 和 List<?>

java - 使用apache poi 3.9迭代写入xlsx文档时出现异常

java apache poi shifting Rows 遇到运行时异常

java - Excel在循环过程中的列分布行为,可能吗?

java - Apache POI hsmf 对 getMesssageDate 返回 null