KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > security > spec > RSAMultiPrimePrivateCrtKeySpec


1 /*
2  * @(#)RSAMultiPrimePrivateCrtKeySpec.java 1.8 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.security.spec;
9
10 import java.math.BigInteger JavaDoc;
11
12 /**
13  * This class specifies an RSA multi-prime private key, as defined in the
14  * PKCS#1 v2.1, using the Chinese Remainder Theorem (CRT) information
15  * values for efficiency.
16  *
17  * @author Valerie Peng
18  *
19  * @version 1.8 03/12/19
20  *
21  * @see java.security.Key
22  * @see java.security.KeyFactory
23  * @see KeySpec
24  * @see PKCS8EncodedKeySpec
25  * @see RSAPrivateKeySpec
26  * @see RSAPublicKeySpec
27  * @see RSAOtherPrimeInfo
28  *
29  * @since 1.4
30  */

31
32 public class RSAMultiPrimePrivateCrtKeySpec extends RSAPrivateKeySpec JavaDoc {
33
34     private final BigInteger JavaDoc publicExponent;
35     private final BigInteger JavaDoc primeP;
36     private final BigInteger JavaDoc primeQ;
37     private final BigInteger JavaDoc primeExponentP;
38     private final BigInteger JavaDoc primeExponentQ;
39     private final BigInteger JavaDoc crtCoefficient;
40     private final RSAOtherPrimeInfo JavaDoc otherPrimeInfo[];
41
42    /**
43     * Creates a new <code>RSAMultiPrimePrivateCrtKeySpec</code>
44     * given the modulus, publicExponent, privateExponent,
45     * primeP, primeQ, primeExponentP, primeExponentQ,
46     * crtCoefficient, and otherPrimeInfo as defined in PKCS#1 v2.1.
47     *
48     * <p>Note that the contents of <code>otherPrimeInfo</code>
49     * are copied to protect against subsequent modification when
50     * constructing this object.
51     *
52     * @param modulus the modulus n.
53     * @param publicExponent the public exponent e.
54     * @param privateExponent the private exponent d.
55     * @param primeP the prime factor p of n.
56     * @param primeQ the prime factor q of n.
57     * @param primeExponentP this is d mod (p-1).
58     * @param primeExponentQ this is d mod (q-1).
59     * @param crtCoefficient the Chinese Remainder Theorem
60     * coefficient q-1 mod p.
61     * @param otherPrimeInfo triplets of the rest of primes, null can be
62     * specified if there are only two prime factors (p and q).
63     * @exception NullPointerException if any of the parameters, i.e.
64     * <code>modulus</code>,
65     * <code>publicExponent</code>, <code>privateExponent</code>,
66     * <code>primeP</code>, <code>primeQ</code>,
67     * <code>primeExponentP</code>, <code>primeExponentQ</code>,
68     * <code>crtCoefficient</code>, is null.
69     * @exception IllegalArgumentException if an empty, i.e. 0-length,
70     * <code>otherPrimeInfo</code> is specified.
71     */

72     public RSAMultiPrimePrivateCrtKeySpec(BigInteger JavaDoc modulus,
73                 BigInteger JavaDoc publicExponent,
74                 BigInteger JavaDoc privateExponent,
75                 BigInteger JavaDoc primeP,
76                 BigInteger JavaDoc primeQ,
77                 BigInteger JavaDoc primeExponentP,
78                 BigInteger JavaDoc primeExponentQ,
79                 BigInteger JavaDoc crtCoefficient,
80                 RSAOtherPrimeInfo JavaDoc[] otherPrimeInfo) {
81     super(modulus, privateExponent);
82     if (modulus == null) {
83         throw new NullPointerException JavaDoc("the modulus parameter must be " +
84                         "non-null");
85     }
86     if (publicExponent == null) {
87         throw new NullPointerException JavaDoc("the publicExponent parameter " +
88                         "must be non-null");
89     }
90     if (privateExponent == null) {
91         throw new NullPointerException JavaDoc("the privateExponent parameter " +
92                         "must be non-null");
93     }
94     if (primeP == null) {
95         throw new NullPointerException JavaDoc("the primeP parameter " +
96                         "must be non-null");
97     }
98     if (primeQ == null) {
99         throw new NullPointerException JavaDoc("the primeQ parameter " +
100                         "must be non-null");
101     }
102     if (primeExponentP == null) {
103         throw new NullPointerException JavaDoc("the primeExponentP parameter " +
104                         "must be non-null");
105     }
106     if (primeExponentQ == null) {
107         throw new NullPointerException JavaDoc("the primeExponentQ parameter " +
108                         "must be non-null");
109     }
110     if (crtCoefficient == null) {
111         throw new NullPointerException JavaDoc("the crtCoefficient parameter " +
112                         "must be non-null");
113     }
114     this.publicExponent = publicExponent;
115     this.primeP = primeP;
116     this.primeQ = primeQ;
117     this.primeExponentP = primeExponentP;
118     this.primeExponentQ = primeExponentQ;
119     this.crtCoefficient = crtCoefficient;
120     if (otherPrimeInfo == null) {
121         this.otherPrimeInfo = null;
122     } else if (otherPrimeInfo.length == 0) {
123         throw new IllegalArgumentException JavaDoc("the otherPrimeInfo " +
124                         "parameter must not be empty");
125     } else {
126         this.otherPrimeInfo = (RSAOtherPrimeInfo JavaDoc[])otherPrimeInfo.clone();
127     }
128     }
129
130     /**
131      * Returns the public exponent.
132      *
133      * @return the public exponent.
134      */

135     public BigInteger JavaDoc getPublicExponent() {
136     return this.publicExponent;
137     }
138
139     /**
140      * Returns the primeP.
141      *
142      * @return the primeP.
143      */

144     public BigInteger JavaDoc getPrimeP() {
145     return this.primeP;
146     }
147
148     /**
149      * Returns the primeQ.
150      *
151      * @return the primeQ.
152      */

153     public BigInteger JavaDoc getPrimeQ() {
154     return this.primeQ;
155     }
156
157     /**
158      * Returns the primeExponentP.
159      *
160      * @return the primeExponentP.
161      */

162     public BigInteger JavaDoc getPrimeExponentP() {
163     return this.primeExponentP;
164     }
165
166     /**
167      * Returns the primeExponentQ.
168      *
169      * @return the primeExponentQ.
170      */

171     public BigInteger JavaDoc getPrimeExponentQ() {
172     return this.primeExponentQ;
173     }
174
175     /**
176      * Returns the crtCoefficient.
177      *
178      * @return the crtCoefficient.
179      */

180     public BigInteger JavaDoc getCrtCoefficient() {
181     return this.crtCoefficient;
182     }
183     
184     /**
185      * Returns a copy of the otherPrimeInfo or null if there are
186      * only two prime factors (p and q).
187      *
188      * @return the otherPrimeInfo. Returns a new array each
189      * time this method is called.
190      */

191     public RSAOtherPrimeInfo JavaDoc[] getOtherPrimeInfo() {
192     if (otherPrimeInfo == null) return null;
193     return (RSAOtherPrimeInfo JavaDoc[]) otherPrimeInfo.clone();
194     }
195 }
196
Popular Tags