我正在尝试解密一个s/mime加密的附件(从Outlook/Exchange,smime.p7m)在安卓上使用Bouncycastle。
我可以在Windows上使用p7mViewer解密/查看内容。
代码,如bc-java中的ReadEncryptedMail.java:
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)
我遗漏了什么?
发布于 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。
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);
}https://stackoverflow.com/questions/46957942
复制相似问题