~brian-thomason/+junk/bouncycastle

« back to all changes in this revision

Viewing changes to src/org/bouncycastle/cms/jcajce/JceKEKEnvelopedRecipient.java

  • Committer: Brian Thomason
  • Date: 2011-12-20 17:20:32 UTC
  • Revision ID: brian.thomason@canonical.com-20111220172032-rdtm13jgdxtksacr
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.bouncycastle.cms.jcajce;
 
2
 
 
3
import java.io.InputStream;
 
4
import java.security.Key;
 
5
 
 
6
import javax.crypto.Cipher;
 
7
import javax.crypto.CipherInputStream;
 
8
import javax.crypto.SecretKey;
 
9
 
 
10
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
 
11
import org.bouncycastle.cms.CMSException;
 
12
import org.bouncycastle.cms.RecipientOperator;
 
13
import org.bouncycastle.operator.InputDecryptor;
 
14
 
 
15
public class JceKEKEnvelopedRecipient
 
16
    extends JceKEKRecipient
 
17
{
 
18
    public JceKEKEnvelopedRecipient(SecretKey recipientKey)
 
19
    {
 
20
        super(recipientKey);
 
21
    }
 
22
 
 
23
    public RecipientOperator getRecipientOperator(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentEncryptionAlgorithm, byte[] encryptedContentEncryptionKey)
 
24
        throws CMSException
 
25
    {
 
26
        Key secretKey = extractSecretKey(keyEncryptionAlgorithm, contentEncryptionAlgorithm, encryptedContentEncryptionKey);
 
27
 
 
28
        final Cipher dataCipher = contentHelper.createContentCipher(secretKey, contentEncryptionAlgorithm);
 
29
 
 
30
        return new RecipientOperator(new InputDecryptor()
 
31
        {
 
32
            public AlgorithmIdentifier getAlgorithmIdentifier()
 
33
            {
 
34
                return contentEncryptionAlgorithm;
 
35
            }
 
36
 
 
37
            public InputStream getInputStream(InputStream dataOut)
 
38
            {
 
39
                return new CipherInputStream(dataOut, dataCipher);
 
40
            }
 
41
        });
 
42
    }
 
43
}