KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > util > crypto > params > DHParameters


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.util.crypto.params;
19
20 import java.math.BigInteger JavaDoc;
21
22 import org.apache.geronimo.util.crypto.CipherParameters;
23
24 public class DHParameters
25     implements CipherParameters
26 {
27     private BigInteger JavaDoc g;
28     private BigInteger JavaDoc p;
29     private BigInteger JavaDoc q;
30     private int j;
31     private DHValidationParameters validation;
32
33     public DHParameters(
34         BigInteger JavaDoc p,
35         BigInteger JavaDoc g)
36     {
37         this.g = g;
38         this.p = p;
39     }
40
41     public DHParameters(
42         BigInteger JavaDoc p,
43         BigInteger JavaDoc g,
44         BigInteger JavaDoc q,
45         int j)
46     {
47         this.g = g;
48         this.p = p;
49         this.q = q;
50         this.j = j;
51     }
52
53     public DHParameters(
54         BigInteger JavaDoc p,
55         BigInteger JavaDoc g,
56         BigInteger JavaDoc q,
57         int j,
58         DHValidationParameters validation)
59     {
60         this.g = g;
61         this.p = p;
62         this.q = q;
63         this.j = j;
64     }
65
66     public BigInteger JavaDoc getP()
67     {
68         return p;
69     }
70
71     public BigInteger JavaDoc getG()
72     {
73         return g;
74     }
75
76     public BigInteger JavaDoc getQ()
77     {
78         return q;
79     }
80
81     /**
82      * Return the private value length in bits - if set, zero otherwise (use bitLength(P) - 1).
83      *
84      * @return the private value length in bits, zero otherwise.
85      */

86     public int getJ()
87     {
88         return j;
89     }
90
91     public DHValidationParameters getValidationParameters()
92     {
93         return validation;
94     }
95
96     public boolean equals(
97         Object JavaDoc obj)
98     {
99         if (!(obj instanceof DHParameters))
100         {
101             return false;
102         }
103
104         DHParameters pm = (DHParameters)obj;
105
106         if (this.getValidationParameters() != null)
107         {
108             if (!this.getValidationParameters().equals(pm.getValidationParameters()))
109             {
110                 return false;
111             }
112         }
113         else
114         {
115             if (pm.getValidationParameters() != null)
116             {
117                 return false;
118             }
119         }
120
121         if (this.getQ() != null)
122         {
123             if (!this.getQ().equals(pm.getQ()))
124             {
125                 return false;
126             }
127         }
128         else
129         {
130             if (pm.getQ() != null)
131             {
132                 return false;
133             }
134         }
135
136         return (j == pm.getJ()) && pm.getP().equals(p) && pm.getG().equals(g);
137     }
138 }
139
Popular Tags