2017-10-26 14 views
0

Bouncycastleを使用してAndroidでs/mimeで暗号化された添付ファイル(Outlook/Exchange、smime.p7mから)を復号しようとしています。復号化smime.p7m

Windows上でp7mViewerを使用して内容を復号化/表示できます。結果

ByteArrayInputStream inputStream = new ByteArrayInputStream(encryptedContent); 
Session session = Session.getInstance(new Properties()); 
MimeMessage mimeMessage = new MimeMessage(session, inputStream);  
SMIMEEnveloped smimeEnveloped = new SMIMEEnveloped(mimeMessage); 

iがにjava.io.IOExceptionを得る:BC-JavaからReadEncryptedMail.java等

コード、DER長以上の4バイト:75 org.bouncycastle.asn1.ASN1InputStreamで.readLength(不明ソース:53)

私は何が欠けていますか?

答えて

0

掘りの多くは、私が正常に解析さCMSEnvelopedDataParserをしようとする私を導くのEnvelopedDataのコンテンツタイプを持ったコードではBouncyCastleメーリングリストhttp://bouncy-castle.1462172.n4.nabble.com/how-to-generically-parse-a-PKCS7-object-td1467990.html

の「包括的PKCS7オブジェクトを解析する方法を」見つけた後、コンテンツ。

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); 
}