1
package org.bouncycastle.asn1.cms;
3
import org.bouncycastle.asn1.ASN1EncodableVector;
4
import org.bouncycastle.asn1.ASN1OctetString;
5
import org.bouncycastle.asn1.ASN1Sequence;
6
import org.bouncycastle.asn1.ASN1TaggedObject;
7
import org.bouncycastle.asn1.ASN1Encodable;
8
import org.bouncycastle.asn1.DERInteger;
9
import org.bouncycastle.asn1.DERObject;
10
import org.bouncycastle.asn1.DERSequence;
11
import org.bouncycastle.asn1.DERTaggedObject;
12
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
14
public class PasswordRecipientInfo
17
private DERInteger version;
18
private AlgorithmIdentifier keyDerivationAlgorithm;
19
private AlgorithmIdentifier keyEncryptionAlgorithm;
20
private ASN1OctetString encryptedKey;
22
public PasswordRecipientInfo(
23
AlgorithmIdentifier keyEncryptionAlgorithm,
24
ASN1OctetString encryptedKey)
26
this.version = new DERInteger(0);
27
this.keyEncryptionAlgorithm = keyEncryptionAlgorithm;
28
this.encryptedKey = encryptedKey;
31
public PasswordRecipientInfo(
32
AlgorithmIdentifier keyDerivationAlgorithm,
33
AlgorithmIdentifier keyEncryptionAlgorithm,
34
ASN1OctetString encryptedKey)
36
this.version = new DERInteger(0);
37
this.keyDerivationAlgorithm = keyDerivationAlgorithm;
38
this.keyEncryptionAlgorithm = keyEncryptionAlgorithm;
39
this.encryptedKey = encryptedKey;
42
public PasswordRecipientInfo(
45
version = (DERInteger)seq.getObjectAt(0);
46
if (seq.getObjectAt(1) instanceof ASN1TaggedObject)
48
keyDerivationAlgorithm = AlgorithmIdentifier.getInstance((ASN1TaggedObject)seq.getObjectAt(1), false);
49
keyEncryptionAlgorithm = AlgorithmIdentifier.getInstance(seq.getObjectAt(2));
50
encryptedKey = (ASN1OctetString)seq.getObjectAt(3);
54
keyEncryptionAlgorithm = AlgorithmIdentifier.getInstance(seq.getObjectAt(1));
55
encryptedKey = (ASN1OctetString)seq.getObjectAt(2);
60
* return a PasswordRecipientInfo object from a tagged object.
62
* @param obj the tagged object holding the object we want.
63
* @param explicit true if the object is meant to be explicitly
64
* tagged false otherwise.
65
* @exception IllegalArgumentException if the object held by the
66
* tagged object cannot be converted.
68
public static PasswordRecipientInfo getInstance(
72
return getInstance(ASN1Sequence.getInstance(obj, explicit));
76
* return a PasswordRecipientInfo object from the given object.
78
* @param obj the object we want converted.
79
* @exception IllegalArgumentException if the object cannot be converted.
81
public static PasswordRecipientInfo getInstance(
84
if (obj == null || obj instanceof PasswordRecipientInfo)
86
return (PasswordRecipientInfo)obj;
89
if(obj instanceof ASN1Sequence)
91
return new PasswordRecipientInfo((ASN1Sequence)obj);
94
throw new IllegalArgumentException("Invalid PasswordRecipientInfo: " + obj.getClass().getName());
97
public DERInteger getVersion()
102
public AlgorithmIdentifier getKeyDerivationAlgorithm()
104
return keyDerivationAlgorithm;
107
public AlgorithmIdentifier getKeyEncryptionAlgorithm()
109
return keyEncryptionAlgorithm;
112
public ASN1OctetString getEncryptedKey()
118
* Produce an object suitable for an ASN1OutputStream.
120
* PasswordRecipientInfo ::= SEQUENCE {
121
* version CMSVersion, -- Always set to 0
122
* keyDerivationAlgorithm [0] KeyDerivationAlgorithmIdentifier
124
* keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
125
* encryptedKey EncryptedKey }
128
public DERObject toASN1Object()
130
ASN1EncodableVector v = new ASN1EncodableVector();
134
if (keyDerivationAlgorithm != null)
136
v.add(new DERTaggedObject(false, 0, keyDerivationAlgorithm));
138
v.add(keyEncryptionAlgorithm);
141
return new DERSequence(v);