首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解密smime.p7m

解密smime.p7m
EN

Stack Overflow用户
提问于 2017-10-26 23:11:42
回答 1查看 1.2K关注 0票数 0

我正在尝试解密一个s/mime加密的附件(从Outlook/Exchange,smime.p7m)在安卓上使用Bouncycastle。

我可以在Windows上使用p7mViewer解密/查看内容。

代码,如bc-java中的ReadEncryptedMail.java:

代码语言:javascript
复制
ByteArrayInputStream inputStream = new ByteArrayInputStream(encryptedContent);
Session session = Session.getInstance(new Properties());
MimeMessage mimeMessage = new MimeMessage(session, inputStream);    
SMIMEEnveloped smimeEnveloped = new SMIMEEnveloped(mimeMessage);

结果,我在org.bouncycastle.asn1.ASN1InputStream.readLength(Unknown上得到了java.io.IOException: DER长度超过4个字节: 75 (来源:53)

我遗漏了什么?

EN

回答 1

Stack Overflow用户

发布于 2017-10-27 20:55:07

经过大量的挖掘,我在bouncycastle邮件列表http://bouncy-castle.1462172.n4.nabble.com/how-to-generically-parse-a-PKCS7-object-td1467990.html上找到了“如何通用地解析PKCS7对象”

使用代码,我得到了ENVELOPEDDATA的内容类型,这使我尝试使用一个成功解析内容的CMSEnvelopedDataParser。

代码语言:javascript
复制
CMSEnvelopedDataParser cmsEnvelopedDataParser = new CMSEnvelopedDataParser(encryptedContent);
Collection recInfos = cmsEnvelopedDataParser.getRecipientInfos().getRecipients();
Iterator recipientIterator = recInfos.iterator();
if (recipientIterator.hasNext()) {
    RecipientInformation recipientInformation = (RecipientInformation) recipientIterator.next();
    byte[] contentBytes = recipientInformation.getContent(new JceKeyTransEnvelopedRecipient(privateKey));
    String content = new String(contentBytes);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46957942

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档