Example usage for org.bouncycastle.cms.bc BcRSAKeyTransRecipientInfoGenerator BcRSAKeyTransRecipientInfoGenerator

List of usage examples for org.bouncycastle.cms.bc BcRSAKeyTransRecipientInfoGenerator BcRSAKeyTransRecipientInfoGenerator

Introduction

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

Prototype

public BcRSAKeyTransRecipientInfoGenerator(X509CertificateHolder recipientCert) throws IOException 

Source Link

Usage

From source file:org.apache.kerby.pkix.EnvelopedDataEngine.java

License:Apache License

/**
 * Uses a certificate to encrypt data in a CMS EnvelopedData structure and
 * returns the encoded EnvelopedData as bytes.
 * <p/>// ww w.ja v  a2 s .co m
 * 'encKeyPack' contains a CMS type ContentInfo encoded according to [RFC3852].
 * The contentType field of the type ContentInfo is id-envelopedData (1.2.840.113549.1.7.3).
 * The content field is an EnvelopedData. The contentType field for the type
 * EnvelopedData is id-signedData (1.2.840.113549.1.7.2).
 *
 * @param dataToEnvelope
 * @param certificate
 * @return The EnvelopedData bytes.
 * @throws IOException
 * @throws CMSException
 * @throws CertificateEncodingException
 */
public static byte[] getEnvelopedReplyKeyPack(byte[] dataToEnvelope, X509Certificate certificate)
        throws IOException, CMSException, CertificateEncodingException {
    CMSProcessableByteArray content = new CMSProcessableByteArray(dataToEnvelope);

    CMSEnvelopedDataGenerator envelopeGenerator = new CMSEnvelopedDataGenerator();
    envelopeGenerator.addRecipientInfoGenerator(
            new BcRSAKeyTransRecipientInfoGenerator(new JcaX509CertificateHolder(certificate)));
    CMSEnvelopedData envdata = envelopeGenerator.generate(content,
            new BcCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC).build());

    return envdata.getEncoded();
}