KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > oyster > crypto > AlgorithmChecker


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

7
8
9 package org.enhydra.oyster.crypto;
10
11 import org.enhydra.oyster.exception.SMIMEException;
12
13
14 /**
15  * AlgorithmChecker class represents check point for input parameters for the
16  * symmetric encryption. Algorithm names and corresponding key length are:<BR>
17  * DES - 56<BR>
18  * DES_EDE3_CBC - 128, 192<BR>
19  * RC2_CBC - 40, 64, 128<BR>
20  */

21 public class AlgorithmChecker {
22
23 /**
24  * Symetric key size which will be returned by getKeySize method.
25  */

26   private static int keySizeInBits = 0;
27
28 /**
29  * Algorithm name which will be returned by getAlgorithmName method.
30  */

31   private String JavaDoc algorithmName = null;
32
33 /**
34  * Object construction with the given name of algorithm and key size in bits.
35  * This constructor performs checking of the imported parameters of the
36  * algorithm and defines specific names for later use in Chiper class.
37  * @param algorithm0 name of the one of the following algorithms: "DES",
38  * "DES_EDE3_CBC" and "RC2_CBC".
39  * @param keySize0 key size in bits.
40  * @exception SMIMEException in case of invalid algorithm names, or in case
41  * of wrong key sizes in bits.
42  */

43   public AlgorithmChecker (String JavaDoc algorithm0, int keySize0) throws SMIMEException
44   {
45     if (!algorithm0.equalsIgnoreCase("DES") &&
46                       !algorithm0.equalsIgnoreCase("RC2_CBC") &&
47                       !algorithm0.equals("DES_EDE3_CBC")) {
48       throw new SMIMEException(this, 1013);
49     }
50     if (algorithm0.equalsIgnoreCase("RC2_CBC")) {
51       algorithmName = "RC2";
52       if (keySize0 != 40 && keySize0 != 64 && keySize0 != 128)
53         throw new SMIMEException(this, 1014);
54       keySizeInBits = keySize0;
55     }
56     else if (algorithm0.equalsIgnoreCase("DES_EDE3_CBC")) {
57       algorithmName = "DESede";
58       if (keySize0 != 128 && keySize0 != 192)
59         throw new SMIMEException(this, 1015);
60       keySizeInBits = keySize0;
61     }
62     else {
63       algorithmName = "DES";
64       if (keySize0 != 56)
65         throw new SMIMEException(this, 1016);
66       keySizeInBits = keySize0;
67     }
68   }
69
70 /**
71  * Returns algorithm name used in the symmetric encryption.
72  * @return Name of the chosen algorithm for symmetric encryption.
73  */

74   public String JavaDoc getAlgorithmName () {
75     return algorithmName;
76   }
77
78 /**
79  * Returns key size in bits which is used in the symmetric algorithm.
80  * @return Key size in bits for the algorithm used in the symmetric encryption.
81  */

82   public int getKeySize () {
83     return keySizeInBits;
84   }
85 }
86
87
88
89
Popular Tags