Example usage for org.bouncycastle.cms KeyTransRecipientId KeyTransRecipientId

List of usage examples for org.bouncycastle.cms KeyTransRecipientId KeyTransRecipientId

Introduction

In this page you can find the example usage for org.bouncycastle.cms KeyTransRecipientId KeyTransRecipientId.

Prototype

public KeyTransRecipientId(byte[] subjectKeyId) 

Source Link

Document

Construct a key trans recipient ID with the value of a public key's subjectKeyId.

Usage

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. j a va 2s .  c o  m
    RecipientId fileRecipientId = null;
    if (recipientInfo.getRID() != null) {
        fileRecipientId = recipientInfo.getRID();
    }
    byte[] result = recipientInfo.getContent(recipient);
    return result;
}