1
package org.bouncycastle.asn1.cms;
3
import org.bouncycastle.asn1.ASN1Encodable;
4
import org.bouncycastle.asn1.ASN1EncodableVector;
5
import org.bouncycastle.asn1.ASN1OctetString;
6
import org.bouncycastle.asn1.ASN1Sequence;
7
import org.bouncycastle.asn1.ASN1TaggedObject;
8
import org.bouncycastle.asn1.DERInteger;
9
import org.bouncycastle.asn1.DERObject;
10
import org.bouncycastle.asn1.DERSequence;
11
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
13
public class KEKRecipientInfo
16
private DERInteger version;
17
private KEKIdentifier kekid;
18
private AlgorithmIdentifier keyEncryptionAlgorithm;
19
private ASN1OctetString encryptedKey;
21
public KEKRecipientInfo(
23
AlgorithmIdentifier keyEncryptionAlgorithm,
24
ASN1OctetString encryptedKey)
26
this.version = new DERInteger(4);
28
this.keyEncryptionAlgorithm = keyEncryptionAlgorithm;
29
this.encryptedKey = encryptedKey;
32
public KEKRecipientInfo(
35
version = (DERInteger)seq.getObjectAt(0);
36
kekid = KEKIdentifier.getInstance(seq.getObjectAt(1));
37
keyEncryptionAlgorithm = AlgorithmIdentifier.getInstance(seq.getObjectAt(2));
38
encryptedKey = (ASN1OctetString)seq.getObjectAt(3);
42
* return a KEKRecipientInfo object from a tagged object.
44
* @param obj the tagged object holding the object we want.
45
* @param explicit true if the object is meant to be explicitly
46
* tagged false otherwise.
47
* @exception IllegalArgumentException if the object held by the
48
* tagged object cannot be converted.
50
public static KEKRecipientInfo getInstance(
54
return getInstance(ASN1Sequence.getInstance(obj, explicit));
58
* return a KEKRecipientInfo object from the given object.
60
* @param obj the object we want converted.
61
* @exception IllegalArgumentException if the object cannot be converted.
63
public static KEKRecipientInfo getInstance(
66
if (obj == null || obj instanceof KEKRecipientInfo)
68
return (KEKRecipientInfo)obj;
71
if(obj instanceof ASN1Sequence)
73
return new KEKRecipientInfo((ASN1Sequence)obj);
76
throw new IllegalArgumentException("Invalid KEKRecipientInfo: " + obj.getClass().getName());
79
public DERInteger getVersion()
84
public KEKIdentifier getKekid()
89
public AlgorithmIdentifier getKeyEncryptionAlgorithm()
91
return keyEncryptionAlgorithm;
94
public ASN1OctetString getEncryptedKey()
100
* Produce an object suitable for an ASN1OutputStream.
102
* KEKRecipientInfo ::= SEQUENCE {
103
* version CMSVersion, -- always set to 4
104
* kekid KEKIdentifier,
105
* keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
106
* encryptedKey EncryptedKey
110
public DERObject toASN1Object()
112
ASN1EncodableVector v = new ASN1EncodableVector();
116
v.add(keyEncryptionAlgorithm);
119
return new DERSequence(v);