在其中带有附件的MimeBodyPart上签名(带有Bouncycastle) [英] Sign MimeBodyPart which has attachments in it (with Bouncycastle)

查看:378
本文介绍了在其中带有附件的MimeBodyPart上签名(带有Bouncycastle)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OpenAS2Server-1.3.3库. 在那里发送单个文档工作正常.

I am working with OpenAS2Server-1.3.3 library. There sending a single document is working fine..

现在,我想对其进行修改以发送带有附件的文档,就像处理电子邮件一样.在这种情况下,所有解密都可以正常工作,但是签名验证失败(MIC不匹配)

Now I wanted to modify it to send document with attachments, like we do with emails. In this scenario, all the decription work well, but signature verification failed (MIC is not matched)

这就是我要发送带有主要文档的附件的方式: 创建一个MimeMultipart并将两个MimeBodyPart添加到其中. (主要文件和附件) 最后将MimeMultipart包裹在MimeBodyPart中(我不确定这是这样做的方法,但是无论如何Bouncycastle没有API来对MimeMultipart进行签名)

This is how I am tring to send attachments with main doc: Create a MimeMultipart and add two MimeBodyPart into it. (main document and the attachment) Finally wrap the MimeMultipart within a MimeBodyPart (I am not sure this is the way to do this, but anyway Bouncycastle do not have API to sign MimeMultipart )

有人可以告诉我对带有附件的邮件进行签名的正确方法吗?

Could anyone tell me the correct way to sign a message with attachment ?

        MimeBodyPart mainBody = new MimeBodyPart();
        mainBody.setDataHandler(new DataHandler(byteSource));

        MimeBodyPart attachemt1 = new MimeBodyPart();
        attachemt1.attachFile("/home/user/Desktop/Test1.txt");

        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(mainBody);
        multipart.addBodyPart(attachemt1);

        MimeBodyPart body = new MimeBodyPart();
        body.setContent(multipart);
        body.setHeader("Content-Type", multipart.getContentType());
        logger.info("--------------Attaching the file...  Done");

推荐答案

我能够找到问题和解决方案.我只是将它放在这里,供其他尝试进行此类工作的人使用.

I was able to get the issue and solution. I am just putting it here for anyone else who will try to do this kind of work.

我只是在发送端和接收端转储用于计算MIC的数据.因此,所附图像将清楚地显示问题.

I just dump the data that use for calculating MIC, at both sending side and receiving side. So the attached image will show the problem clearly.

因此,我在发送方手动为所有附件和主要文档添加了以下标头字段,如下所示.

So I added those header fields manually for all the attachments and main doc, at the sending side, as bellow.

mainBody.setHeader("Content-Type", "application/EDI-X12");
mainBody.setHeader("Content-Transfer-Encoding", "7bit");

现在解决了,并且"MIC已匹配".

Now it solved and "MIC is matched".

这篇关于在其中带有附件的MimeBodyPart上签名(带有Bouncycastle)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆