KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > oyster > cms > EncryptedContentInfo


1 /*
2  * Title: Oyster Project
3  * Description: S/MIME email sending capabilities
4  * @Author Vladimir Radisic
5  * @Version 2.1.5
6  */

7
8
9 package org.enhydra.oyster.cms;
10
11 import org.enhydra.oyster.exception.SMIMEException;
12 import org.enhydra.oyster.der.DERSequencePr;
13
14
15 /**
16  * EncryptedContentInfo class is DER encoded Encrypted Content Info represented
17  * in ASN.1 notation according to RFC2630. This class is used for construction
18  * of CMS object for encrypted messages. Between other information, encrypted content
19  * is stored in the object of this class.<BR>
20  * <BR>
21  * <DL>
22  * EncryptedContentInfo ::= SEQUENCE {<BR>
23  * <DD> contentType ContentType,<BR>
24  * <DD> contentEncryptionAlgorithm ContentEncryptionAlgorithmIdentifier,<BR>
25  * <DD> encryptedContent [0] IMPLICIT EncryptedContent OPTIONAL }<BR>
26  * </DL>
27  * <BR>
28  * ContentType ::= OBJECT IDENTIFIER<BR>
29  * <BR>
30  * <DL>
31  * ContentEncryptionAlgorithmIdentifier ::= SEQUENCE {<BR>
32  * <DD> algorithm AlgorithmIdentifier,<BR>
33  * <DD> parameter RC2CBCParameter }<BR>
34  * </DL>
35  * <BR>
36  * AlgorithmIdentifier ::= OBJECT IDENTIFIER<BR>
37  */

38 public class EncryptedContentInfo extends DERSequencePr {
39
40 /**
41  * Determinate order of adding commponents
42  */

43   int orderIdentifier = 0;
44
45 /**
46  * Constructs empty Encrypted Content Info. All methods: addContentType,
47  * addEncryptAlgorithmID and addEncryptContent must be performed after
48  * construction for obtaining valid CMS object.
49  * @exception SMIMEException thrown from super class constructor.
50  */

51   public EncryptedContentInfo () throws SMIMEException
52   {
53   }
54
55 /**
56  * Adds Content Type
57  * @param contType0 Content Type represented as byte array
58  * @exception SMIMEException if order of adding components is wrong. Also, it
59  * can be thrown from super class addContent method.
60  */

61   public void addContentType (byte[] contType0) throws SMIMEException {
62     if (orderIdentifier == 0) {
63       super.addContent(contType0);
64       orderIdentifier++;
65     }
66     else
67       throw new SMIMEException(this, 1018);
68   }
69
70 /**
71  * Adds Encrypted Algorithm Identifier
72  * @param alg0 Encrypted Algorithm Identifier represented as byte array
73  * @exception SMIMEException if order of adding components is wrong. Also, it
74  * can be thrown from super class addContent method.
75  */

76   public void addEncryptAlgorithmID (byte[] alg0) throws SMIMEException {
77     if (orderIdentifier == 1) {
78       super.addContent(alg0);
79       orderIdentifier++;
80     }
81     else
82       throw new SMIMEException(this, 1018);
83   }
84
85 /**
86  * Adds Encrypted Content
87  * @param cont0 encrypted content as byte array
88  * @exception SMIMEException if order of adding components is wrong. Also, it
89  * can be thrown from super class addContent method.
90  */

91   public void addEncryptContent (byte[] cont0) throws SMIMEException {
92     if (orderIdentifier == 2) {
93       super.addContent(cont0);
94       orderIdentifier++;
95     }
96     else
97       throw new SMIMEException(this, 1018);
98   }
99 }
100
101
102
103
Popular Tags