KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.enhydra.oyster.der.DERInteger;
14 import org.enhydra.oyster.der.DEROctetString;
15
16
17 /**
18  * RC2CBCParameter is parameter used in Content Encryption Algorithm Identifier
19  * in CMS object for encrypted message, for RC2_CBC algorithms. Parameter for
20  * this algorithm is made from initialization vector and key length in bits.<BR>
21  * <BR>
22  * <DL>
23  * RC2CBCParameter ::= SEQUENCE {<BR>
24  * <DD> rc2ParameterVersion INTEGER,<BR>
25  * <DD> iv OCTET STRING }<BR>
26  * </DL>
27  * <BR>
28  * rc2ParameterVersion ::= INTEGER<BR>
29  * <BR>
30  * IV ::= OCTET STRING -- exactly 8 octets<BR>
31  */

32 public class RC2CBCParameter extends DERSequencePr {
33
34 /**
35  * Constructor takes key length in bits and IV (Initialization Vector) as byte
36  * array
37  * @param lenKey0 key length
38  * @param iv0 Initialization Vector
39  * @exception SMIMEException if Initialization Vector - IV is not 8 bytes long
40  * or key size is not 40, 64 or 128. Also, exception could be thrown in
41  * super class constructor or in super class addContent method.
42  */

43   public RC2CBCParameter (int lenKey0, byte[] iv0) throws SMIMEException
44   {
45     int version;
46
47     if (lenKey0 == 40)
48       version = 160;
49     else if (lenKey0 == 64)
50       version = 120;
51     else if (lenKey0 == 128)
52       version = 58;
53     else
54       throw new SMIMEException(this, 1014);
55     super.addContent(new DERInteger(version).getDEREncoded());
56     if (iv0.length != 8)
57       throw new SMIMEException(this, 1012);
58     super.addContent(new DEROctetString(iv0).getDEREncoded());
59   }
60 }
61
62
63
64
Popular Tags