KickJava   Java API By Example, From Geeks To Geeks.

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


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.DERSet;
13 import org.enhydra.oyster.der.DERSequence;
14 import org.enhydra.oyster.der.DERInteger;
15
16 /**
17  * Capabilities which this class can indicate are capabilities of symetric
18  * encryption algorithm: DES_EDE3_CBC, RC2_CBC with 128bit key, RC2_CBC with
19  * 64bit key, DES and RC2_CBC with 40bit key. Capabilities Attributes are one of
20  * Signed Attributes and are used for creating CMS objects for signed messages.
21  */

22 public class CapabilitiesAttribute extends Attribute {
23
24 /**
25  * Constructs capabilities from given list with information about algorithm
26  * @param capabilities0 is array of Strings with element corresponds to
27  * appropriate algorithm (list of algorithms).
28  * @exception SMIMEException in case of unknown type of Capabilities Attributes.
29  * Also, it can be thrown from super class constructor or its addContent method.
30  */

31   public CapabilitiesAttribute (String JavaDoc[] capabilities0) throws SMIMEException
32   {
33     super("ID_SMIMECAPABILITIES", "NAME_STRING");
34     DERSet capabilSet = new DERSet();
35     DERSequence capabilSequ = new DERSequence();
36     for (int i = 0; i != capabilities0.length; i++) {
37       if (capabilities0[i] == null)
38         continue;
39       else if (capabilities0[i].equalsIgnoreCase("RC2_CBC_40") | capabilities0[i].equalsIgnoreCase("RC2_CBC_64") | capabilities0[i].equalsIgnoreCase("RC2_CBC_128")) {
40         AlgorithmIdentifier rc2 = new AlgorithmIdentifier("RC2_CBC", "NAME_STRING");
41         Integer JavaDoc keyLeng = new Integer JavaDoc(capabilities0[i].substring(9));
42         rc2.addParamToAlgorithmId((new DERInteger(keyLeng.intValue())).getDEREncoded());
43         capabilSequ.addContent(rc2.getDEREncoded());
44       }
45       else if (capabilities0[i].equalsIgnoreCase("DES_EDE3_CBC") | capabilities0[i].equalsIgnoreCase("DES")) {
46         AlgorithmIdentifier desede3 = new AlgorithmIdentifier(capabilities0[i], "NAME_STRING");
47         desede3.addNullToAlgorithmId();
48         capabilSequ.addContent(desede3.getDEREncoded());
49       }
50       else if (capabilities0[i].equalsIgnoreCase("MD2_WITH_RSA") | capabilities0[i].equalsIgnoreCase("MD5_WITH_RSA") | capabilities0[i].equalsIgnoreCase("SHA1_WITH_RSA") | capabilities0[i].equalsIgnoreCase("SHA1_WITH_DSA") | capabilities0[i].equalsIgnoreCase("RSA")) {
51         AlgorithmIdentifier rsa = new AlgorithmIdentifier(capabilities0[i], "NAME_STRING");
52         capabilSequ.addContent(rsa.getDEREncoded());
53       }
54       else
55         throw new SMIMEException(this, 1020);
56     }
57     capabilSet.addContent(capabilSequ.getDEREncoded());
58     super.addContent(capabilSet.getDEREncoded());
59   }
60 }
61
62
63
64
Popular Tags