我有许多带有加密附件的 .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/