2017-10-26 11 views
0

Bouncycastle을 사용하여 Android에서 s/mime 암호화 첨부 파일 (Outlook/Exchange, smime.p7m)을 해독하려고합니다.암호 해독 smime.p7m

Windows에서 p7mViewer를 사용하여 내용을 해독하거나 볼 수 있습니다.

BC 자바에서 ReadEncryptedMail.java 추천 코드 : DER 길이보다 4 바이트 : 난 때 java.io.IOException 얻을 결과

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

75에서 org.bouncycastle.asn1.ASN1InputStream .readLength (알 수 없음 출처 : 53)

내가 무엇이 누락 되었습니까?

답변

0

후 내가 bouncycastle 메일 링리스트 성공적으로 구문 분석 CMSEnvelopedDataParser 시도에 저를 이끌어 내가 ENVELOPEDDATA의 콘텐츠 형식을 가지고 코드와 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); 
}