List of usage examples for org.bouncycastle.mail.smime SMIMEEnveloped SMIMEEnveloped
public SMIMEEnveloped(MimeMessage message) throws MessagingException, CMSException
From source file:org.votingsystem.signature.util.Encryptor.java
License:Open Source License
public static byte[] decryptFile(byte[] encryptedFile, PublicKey publicKey, PrivateKey receiverPrivateKey) throws Exception { RecipientId recId = new KeyTransRecipientId(publicKey.getEncoded()); Recipient recipient = new JceKeyTransEnvelopedRecipient(receiverPrivateKey).setProvider(ContextVS.PROVIDER); MimeMessage msg = new MimeMessage(null, new ByteArrayInputStream(encryptedFile)); SMIMEEnveloped smimeEnveloped = new SMIMEEnveloped(msg); RecipientInformationStore recipients = smimeEnveloped.getRecipientInfos(); RecipientInformation recipientInfo = null; recipientInfo = recipients.get(recId); if (recipientInfo == null && recipients.getRecipients().size() == 1) { recipientInfo = (RecipientInformation) recipients.getRecipients().iterator().next(); }/* ww w . jav a2 s. com*/ RecipientId fileRecipientId = null; if (recipientInfo.getRID() != null) { fileRecipientId = recipientInfo.getRID(); } byte[] result = recipientInfo.getContent(recipient); return result; }