Produced by Araxis Merge on 9/25/2018 2:13:11 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\javax\crypto | KeyGenerator.java | Mon Jan 22 14:46:52 2018 UTC |
2 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\javax\crypto | KeyGenerator.java | Wed Sep 12 17:18:34 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 6 | 1102 |
Changed | 5 | 10 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | /* | |
2 | * Copyrig ht (c) 199 7, 2014, O racle and/ or its aff iliates. A ll rights reserved. | |
3 | * DO NOT ALTER OR R EMOVE COPY RIGHT NOTI CES OR THI S FILE HEA DER. | |
4 | * | |
5 | * This co de is free software; you can r edistribut e it and/o r modify i t | |
6 | * under t he terms o f the GNU General Pu blic Licen se version 2 only, a s | |
7 | * publish ed by the Free Softw are Founda tion. Ora cle design ates this | |
8 | * particu lar file a s subject to the "Cl asspath" e xception a s provided | |
9 | * by Orac le in the LICENSE fi le that ac companied this code. | |
10 | * | |
11 | * This co de is dist ributed in the hope that it wi ll be usef ul, but WI THOUT | |
12 | * ANY WAR RANTY; wit hout even the implie d warranty of MERCHA NTABILITY or | |
13 | * FITNESS FOR A PAR TICULAR PU RPOSE. Se e the GNU General Pu blic Licen se | |
14 | * version 2 for mor e details (a copy is included in the LIC ENSE file that | |
15 | * accompa nied this code). | |
16 | * | |
17 | * You sho uld have r eceived a copy of th e GNU Gene ral Public License v ersion | |
18 | * 2 along with this work; if not, write to the Fr ee Softwar e Foundati on, | |
19 | * Inc., 5 1 Franklin St, Fifth Floor, Bo ston, MA 0 2110-1301 USA. | |
20 | * | |
21 | * Please contact Or acle, 500 Oracle Par kway, Redw ood Shores , CA 94065 USA | |
22 | * or visi t www.orac le.com if you need a dditional informatio n or have any | |
23 | * questio ns. | |
24 | */ | |
25 | ||
26 | package ja vax.crypto ; | |
27 | ||
28 | import jav a.util.*; | |
29 | ||
30 | import jav a.security .*; | |
31 | import jav a.security .Provider. Service; | |
32 | import jav a.security .spec.*; | |
33 | ||
34 | import sun .security. jca.*; | |
35 | import sun .security. jca.GetIns tance.Inst ance; | |
36 | import sun .security. util.Debug ; | |
37 | ||
38 | /** | |
39 | * This cl ass provid es the fun ctionality of a PW (symmetric ) key gene rator. | |
40 | * | |
41 | * <p>Key generators are const ructed usi ng one of the <code> getInstanc e</code> | |
42 | * class m ethods of this class . | |
43 | * | |
44 | * <p>KeyG enerator o bjects are reusable, i.e., aft er a key h as been | |
45 | * generat ed, the sa me KeyGene rator obje ct can be re-used to generate further | |
46 | * keys. | |
47 | * | |
48 | * <p>Ther e are two ways to ge nerate a k ey: in an algorithm- independen t | |
49 | * manner, and in an algorithm -specific manner. | |
50 | * The onl y differen ce between the two i s the init ialization of the ob ject: | |
51 | * | |
52 | * <ul> | |
53 | * <li><b> Algorithm- Independen t Initiali zation</b> | |
54 | * <p>All key genera tors share the conce pts of a < i>keysize< /i> and a | |
55 | * <i>sour ce of rand omness</i> . | |
56 | * There i s an | |
57 | * {@link #init(int, java.secu rity.Secur eRandom) i nit} | |
58 | * method in this Ke yGenerator class tha t takes th ese two un iversally | |
59 | * shared types of a rguments. There is a lso one th at takes j ust a | |
60 | * <code>k eysize</co de> argume nt, and us es the Sec ureRandom implementa tion | |
61 | * of the highest-pr iority ins talled pro vider as t he source of randomn ess | |
62 | * (or a s ystem-prov ided sourc e of rando mness if n one of the installed | |
63 | * provide rs supply a SecureRa ndom imple mentation) , and one that takes just a | |
64 | * source of randomn ess. | |
65 | * | |
66 | * <p>Sinc e no other parameter s are spec ified when you call the above | |
67 | * algorit hm-indepen dent <code >init</cod e> methods , it is up to the | |
68 | * provide r what to do about t he algorit hm-specifi c paramete rs (if any ) to be | |
69 | * associa ted with e ach of the keys. | |
70 | * | |
71 | * <li><b> Algorithm- Specific I nitializat ion</b> | |
72 | * <p>For situations where a s et of algo rithm-spec ific param eters alre ady | |
73 | * exists, there are two | |
74 | * {@link #init(java .security. spec.Algor ithmParame terSpec) i nit} | |
75 | * methods that have an <code> AlgorithmP arameterSp ec</code> | |
76 | * argumen t. One als o has a <c ode>Secure Random</co de> argume nt, while the | |
77 | * other u ses the Se cureRandom implement ation | |
78 | * of the highest-pr iority ins talled pro vider as t he source of randomn ess | |
79 | * (or a s ystem-prov ided sourc e of rando mness if n one of the installed | |
80 | * provide rs supply a SecureRa ndom imple mentation) . | |
81 | * </ul> | |
82 | * | |
83 | * <p>In c ase the cl ient does not explic itly initi alize the KeyGenerat or | |
84 | * (via a call to an <code>ini t</code> m ethod), ea ch provide r must | |
85 | * supply (and docum ent) a def ault initi alization. | |
86 | * | |
87 | * <p> Eve ry impleme ntation of the Java platform i s required to suppor t the | |
88 | * followi ng standar d <code>Ke yGenerator </code> al gorithms w ith the ke ysizes in | |
89 | * parenth eses: | |
90 | * <ul> | |
91 | * <li><tt >AES</tt> (128)</li> | |
92 | * <li><tt >DES</tt> (56)</li> | |
93 | * <li><tt >DESede</t t> (168)</ li> | |
94 | * <li><tt >HmacSHA1< /tt></li> | |
95 | * <li><tt >HmacSHA25 6</tt></li > | |
96 | * </ul> | |
97 | * These a lgorithms are descri bed in the <a href= | |
98 | * "{@docR oot}/../te chnotes/gu ides/secur ity/Standa rdNames.ht ml#KeyGene rator"> | |
99 | * KeyGene rator sect ion</a> of the | |
100 | * Java Cr yptography Architect ure Standa rd Algorit hm Name Do cumentatio n. | |
101 | * Consult the relea se documen tation for your impl ementation to see if any | |
102 | * other a lgorithms are suppor ted. | |
103 | * | |
104 | * @author Jan Luehe | |
105 | * | |
106 | * @see Se cretKey | |
107 | * @since 1.4 | |
108 | */ | |
109 | ||
110 | public cla ss KeyGene rator { | |
111 | ||
112 | privat e static f inal Debug pdebug = | |
113 | Debug. getInstanc e("provide r", "Provi der"); | |
114 | privat e static f inal boole an skipDeb ug = | |
115 | De bug.isOn(" engine=") && !Debug. isOn("keyg enerator") ; | |
116 | ||
117 | // see java.secu rity.KeyPa irGenerato r for fail over notes | |
118 | ||
119 | privat e final st atic int I _NONE = 1; | |
120 | privat e final st atic int I _RANDOM = 2; | |
121 | privat e final st atic int I _PARAMS = 3; | |
122 | privat e final st atic int I _SIZE = 4; | |
123 | ||
124 | // The provider | |
125 | privat e Provider provider; | |
126 | ||
127 | // The provider implementa tion (dele gate) | |
128 | privat e volatile KeyGenera torSpi spi ; | |
129 | ||
130 | // The algorithm | |
131 | privat e final St ring algor ithm; | |
132 | ||
133 | privat e final Ob ject lock = new Obje ct(); | |
134 | ||
135 | privat e Iterator <Service> serviceIte rator; | |
136 | ||
137 | privat e int init Type; | |
138 | privat e int init KeySize; | |
139 | privat e Algorith mParameter Spec initP arams; | |
140 | privat e SecureRa ndom initR andom; | |
141 | ||
142 | /** | |
143 | * Cre ates a Key Generator object. | |
144 | * | |
145 | * @pa ram keyGen Spi the de legate | |
146 | * @pa ram provid er the pro vider | |
147 | * @pa ram algori thm the al gorithm | |
148 | */ | |
149 | protec ted KeyGen erator(Key GeneratorS pi keyGenS pi, Provid er provide r, | |
150 | Str ing algori thm) { | |
151 | th is.spi = k eyGenSpi; | |
152 | th is.provide r = provid er; | |
153 | th is.algorit hm = algor ithm; | |
154 | ||
155 | if (!skipDeb ug && pdeb ug != null ) { | |
156 | pdebug.p rintln("Ke yGenerator ." + algor ithm + " a lgorithm f rom: " + | |
157 | this .provider. getName()) ; | |
158 | } | |
159 | } | |
160 | ||
161 | privat e KeyGener ator(Strin g algorith m) throws NoSuchAlgo rithmExcep tion { | |
162 | th is.algorit hm = algor ithm; | |
163 | Li st<Service > list = | |
164 | GetI nstance.ge tServices( "KeyGenera tor", algo rithm); | |
165 | se rviceItera tor = list .iterator( ); | |
166 | in itType = I _NONE; | |
167 | // fetch and instantia te initial spi | |
168 | if (nextSpi( null, fals e) == null ) { | |
169 | throw ne w NoSuchAl gorithmExc eption | |
170 | (alg orithm + " KeyGenera tor not av ailable"); | |
171 | } | |
172 | ||
173 | if (!skipDeb ug && pdeb ug != null ) { | |
174 | pdebug.p rintln("Ke yGenerator ." + algor ithm + " a lgorithm f rom: " + | |
175 | this .provider. getName()) ; | |
176 | } | |
177 | } | |
178 | ||
179 | /** | |
180 | * Ret urns the a lgorithm n ame of thi s <code>Ke yGenerator </code> ob ject. | |
181 | * | |
182 | * <p> This is th e same nam e that was specified in one of the | |
183 | * <co de>getInst ance</code > calls th at created this | |
184 | * <co de>KeyGene rator</cod e> object. | |
185 | * | |
186 | * @re turn the a lgorithm n ame of thi s <code>Ke yGenerator </code> ob ject. | |
187 | */ | |
188 | public final Str ing getAlg orithm() { | |
189 | re turn this. algorithm; | |
190 | } | |
191 | ||
192 | /** | |
193 | * Returns a <code>Ke yGenerator </code> ob ject that generates PW keys | |
194 | * for the speci fied algor ithm. | |
195 | * | |
196 | * <p> This meth od travers es the lis t of regis tered secu rity Provi ders, | |
197 | * sta rting with the most preferred Provider. | |
198 | * A n ew KeyGene rator obje ct encapsu lating the | |
199 | * Key GeneratorS pi impleme ntation fr om the fir st | |
200 | * Pro vider that supports the specif ied algori thm is ret urned. | |
201 | * | |
202 | * <p> Note that the list of registe red provid ers may be retrieved via | |
203 | * the {@link Se curity#get Providers( ) Security .getProvid ers()} met hod. | |
204 | * | |
205 | * @pa ram algori thm the st andard nam e of the r equested k ey algorit hm. | |
206 | * See the KeyGe nerator se ction in t he <a href = | |
207 | * "{@ docRoot}/. ./technote s/guides/s ecurity/St andardName s.html#Key Generator" > | |
208 | * Jav a Cryptogr aphy Archi tecture St andard Alg orithm Nam e Document ation</a> | |
209 | * for informati on about s tandard al gorithm na mes. | |
210 | * | |
211 | * @re turn the n ew <code>K eyGenerato r</code> o bject. | |
212 | * | |
213 | * @ex ception Nu llPointerE xception i f the spec ified algo rithm is n ull. | |
214 | * | |
215 | * @ex ception No SuchAlgori thmExcepti on if no P rovider su pports a | |
216 | * KeyG eneratorSp i implemen tation for the | |
217 | * spec ified algo rithm. | |
218 | * | |
219 | * @se e java.sec urity.Prov ider | |
220 | */ | |
221 | public static fi nal KeyGen erator get Instance(S tring algo rithm) | |
222 | throws N oSuchAlgor ithmExcept ion { | |
223 | re turn new K eyGenerato r(algorith m); | |
224 | } | |
225 | ||
226 | /** | |
227 | * Returns a <code>Ke yGenerator </code> ob ject that generates PW keys | |
228 | * for the speci fied algor ithm. | |
229 | * | |
230 | * <p> A new Key Generator object enc apsulating the | |
231 | * Key GeneratorS pi impleme ntation fr om the spe cified pro vider | |
232 | * is returned. The speci fied provi der must b e register ed | |
233 | * in the securi ty provide r list. | |
234 | * | |
235 | * <p> Note that the list of registe red provid ers may be retrieved via | |
236 | * the {@link Se curity#get Providers( ) Security .getProvid ers()} met hod. | |
237 | * | |
238 | * @pa ram algori thm the st andard nam e of the r equested k ey algorit hm. | |
239 | * See the KeyGe nerator se ction in t he <a href = | |
240 | * "{@ docRoot}/. ./technote s/guides/s ecurity/St andardName s.html#Key Generator" > | |
241 | * Jav a Cryptogr aphy Archi tecture St andard Alg orithm Nam e Document ation</a> | |
242 | * for informati on about s tandard al gorithm na mes. | |
243 | * | |
244 | * @pa ram provid er the nam e of the p rovider. | |
245 | * | |
246 | * @re turn the n ew <code>K eyGenerato r</code> o bject. | |
247 | * | |
248 | * @ex ception Nu llPointerE xception i f the spec ified algo rithm is n ull. | |
249 | * | |
250 | * @ex ception No SuchAlgori thmExcepti on if a Ke yGenerator Spi | |
251 | * impl ementation for the s pecified a lgorithm i s not | |
252 | * avai lable from the speci fied provi der. | |
253 | * | |
254 | * @ex ception No SuchProvid erExceptio n if the s pecified p rovider is not | |
255 | * regi stered in the securi ty provide r list. | |
256 | * | |
257 | * @ex ception Il legalArgum entExcepti on if the <code>prov ider</code > | |
258 | * is n ull or emp ty. | |
259 | * | |
260 | * @se e java.sec urity.Prov ider | |
261 | */ | |
262 | public static fi nal KeyGen erator get Instance(S tring algo rithm, | |
263 | String p rovider) t hrows NoSu chAlgorith mException , | |
264 | NoSuchPr oviderExce ption { | |
265 | In stance ins tance = Jc eSecurity. getInstanc e("KeyGene rator", | |
266 | KeyG eneratorSp i.class, a lgorithm, provider); | |
267 | re turn new K eyGenerato r((KeyGene ratorSpi)i nstance.im pl, | |
268 | inst ance.provi der, algor ithm); | |
269 | } | |
270 | ||
271 | /** | |
272 | * Returns a <code>Ke yGenerator </code> ob ject that generates PW keys | |
273 | * for the speci fied algor ithm. | |
274 | * | |
275 | * <p> A new Key Generator object enc apsulating the | |
276 | * Key GeneratorS pi impleme ntation fr om the spe cified Pro vider | |
277 | * obj ect is ret urned. No te that th e specifie d Provider object | |
278 | * doe s not have to be reg istered in the provi der list. | |
279 | * | |
280 | * @pa ram algori thm the st andard nam e of the r equested k ey algorit hm. | |
281 | * See the KeyGe nerator se ction in t he <a href = | |
282 | * "{@ docRoot}/. ./technote s/guides/s ecurity/St andardName s.html#Key Generator" > | |
283 | * Jav a Cryptogr aphy Archi tecture St andard Alg orithm Nam e Document ation</a> | |
284 | * for informati on about s tandard al gorithm na mes. | |
285 | * | |
286 | * @pa ram provid er the pro vider. | |
287 | * | |
288 | * @re turn the n ew <code>K eyGenerato r</code> o bject. | |
289 | * | |
290 | * @ex ception Nu llPointerE xception i f the spec ified algo rithm is n ull. | |
291 | * | |
292 | * @ex ception No SuchAlgori thmExcepti on if a Ke yGenerator Spi | |
293 | * impl ementation for the s pecified a lgorithm i s not avai lable | |
294 | * from the speci fied Provi der object . | |
295 | * | |
296 | * @ex ception Il legalArgum entExcepti on if the <code>prov ider</code > | |
297 | * is n ull. | |
298 | * | |
299 | * @se e java.sec urity.Prov ider | |
300 | */ | |
301 | public static fi nal KeyGen erator get Instance(S tring algo rithm, | |
302 | Provider provider) throws No SuchAlgori thmExcepti on { | |
303 | In stance ins tance = Jc eSecurity. getInstanc e("KeyGene rator", | |
304 | KeyG eneratorSp i.class, a lgorithm, provider); | |
305 | re turn new K eyGenerato r((KeyGene ratorSpi)i nstance.im pl, | |
306 | inst ance.provi der, algor ithm); | |
307 | } | |
308 | ||
309 | /** | |
310 | * Ret urns the p rovider of this <cod e>KeyGener ator</code > object. | |
311 | * | |
312 | * @re turn the p rovider of this <cod e>KeyGener ator</code > object | |
313 | */ | |
314 | public final Pro vider getP rovider() { | |
315 | sy nchronized (lock) { | |
316 | disableF ailover(); | |
317 | return p rovider; | |
318 | } | |
319 | } | |
320 | ||
321 | /** | |
322 | * Upd ate the ac tive spi o f this cla ss and ret urn the ne xt | |
323 | * imp lementatio n for fail over. If n o more imp lemenation s are | |
324 | * ava ilable, th is method returns nu ll. Howeve r, the act ive spi of | |
325 | * thi s class is never set to null. | |
326 | */ | |
327 | privat e KeyGener atorSpi ne xtSpi(KeyG eneratorSp i oldSpi, | |
328 | boolean reinit) { | |
329 | sy nchronized (lock) { | |
330 | // someb ody else d id a failo ver concur rently | |
331 | // try t hat spi no w | |
332 | if ((old Spi != nul l) && (old Spi != spi )) { | |
333 | retu rn spi; | |
334 | } | |
335 | if (serv iceIterato r == null) { | |
336 | retu rn null; | |
337 | } | |
338 | while (s erviceIter ator.hasNe xt()) { | |
339 | Serv ice s = se rviceItera tor.next() ; | |
340 | if ( JceSecurit y.canUsePr ovider(s.g etProvider ()) == fal se) { | |
341 | continue; | |
342 | } | |
343 | try { | |
344 | Object ins t = s.newI nstance(nu ll); | |
345 | // ignore non-spis | |
346 | if (inst i nstanceof KeyGenerat orSpi == f alse) { | |
347 | contin ue; | |
348 | } | |
349 | KeyGenerat orSpi spi = (KeyGene ratorSpi)i nst; | |
350 | if (reinit ) { | |
351 | if (in itType == I_SIZE) { | |
352 | sp i.engineIn it(initKey Size, init Random); | |
353 | } else if (initT ype == I_P ARAMS) { | |
354 | sp i.engineIn it(initPar ams, initR andom); | |
355 | } else if (initT ype == I_R ANDOM) { | |
356 | sp i.engineIn it(initRan dom); | |
357 | } else if (initT ype != I_N ONE) { | |
358 | th row new As sertionErr or | |
359 | ("KeyGen erator ini tType: " + initType) ; | |
360 | } | |
361 | } | |
362 | provider = s.getProv ider(); | |
363 | this.spi = spi; | |
364 | return spi ; | |
365 | } ca tch (Excep tion e) { | |
366 | // ignore | |
367 | } | |
368 | } | |
369 | disableF ailover(); | |
370 | return n ull; | |
371 | } | |
372 | } | |
373 | ||
374 | void d isableFail over() { | |
375 | se rviceItera tor = null ; | |
376 | in itType = 0 ; | |
377 | in itParams = null; | |
378 | in itRandom = null; | |
379 | } | |
380 | ||
381 | /** | |
382 | * Ini tializes t his key ge nerator. | |
383 | * | |
384 | * @pa ram random the sourc e of rando mness for this gener ator | |
385 | */ | |
386 | public final voi d init(Sec ureRandom random) { | |
387 | if (serviceI terator == null) { | |
388 | spi.engi neInit(ran dom); | |
389 | return; | |
390 | } | |
391 | Ru ntimeExcep tion failu re = null; | |
392 | Ke yGenerator Spi mySpi = spi; | |
393 | do { | |
394 | try { | |
395 | mySp i.engineIn it(random) ; | |
396 | init Type = I_R ANDOM; | |
397 | init KeySize = 0; | |
398 | init Params = n ull; | |
399 | init Random = r andom; | |
400 | retu rn; | |
401 | } catch (RuntimeEx ception e) { | |
402 | if ( failure == null) { | |
403 | failure = e; | |
404 | } | |
405 | mySp i = nextSp i(mySpi, f alse); | |
406 | } | |
407 | } while (myS pi != null ); | |
408 | th row failur e; | |
409 | } | |
410 | ||
411 | /** | |
412 | * Ini tializes t his key ge nerator wi th the spe cified par ameter set . | |
413 | * | |
414 | * <p> If this k ey generat or require s any rand om bytes, it will ge t them | |
415 | * usi ng the | |
416 | * {@l ink java.s ecurity.Se cureRandom } | |
417 | * imp lementatio n of the h ighest-pri ority inst alled | |
418 | * pro vider as t he source of randomn ess. | |
419 | * (If none of t he install ed provide rs supply an impleme ntation of | |
420 | * Sec ureRandom, a system- provided s ource of r andomness will be us ed.) | |
421 | * | |
422 | * @pa ram params the key g eneration parameters | |
423 | * | |
424 | * @ex ception In validAlgor ithmParame terExcepti on if the given para meters | |
425 | * are inappropr iate for t his key ge nerator | |
426 | */ | |
427 | public final voi d init(Alg orithmPara meterSpec params) | |
428 | th rows Inval idAlgorith mParameter Exception | |
429 | { | |
430 | in it(params, JceSecuri ty.RANDOM) ; | |
431 | } | |
432 | ||
433 | /** | |
434 | * Ini tializes t his key ge nerator wi th the spe cified par ameter | |
435 | * set and a use r-provided source of randomnes s. | |
436 | * | |
437 | * @pa ram params the key g eneration parameters | |
438 | * @pa ram random the sourc e of rando mness for this key g enerator | |
439 | * | |
440 | * @ex ception In validAlgor ithmParame terExcepti on if <cod e>params</ code> is | |
441 | * ina ppropriate for this key genera tor | |
442 | */ | |
443 | public final voi d init(Alg orithmPara meterSpec params, Se cureRandom random) | |
444 | th rows Inval idAlgorith mParameter Exception | |
445 | { | |
446 | if (serviceI terator == null) { | |
447 | spi.engi neInit(par ams, rando m); | |
448 | return; | |
449 | } | |
450 | Ex ception fa ilure = nu ll; | |
451 | Ke yGenerator Spi mySpi = spi; | |
452 | do { | |
453 | try { | |
454 | mySp i.engineIn it(params, random); | |
455 | init Type = I_P ARAMS; | |
456 | init KeySize = 0; | |
457 | init Params = p arams; | |
458 | init Random = r andom; | |
459 | retu rn; | |
460 | } catch (Exception e) { | |
461 | if ( failure == null) { | |
462 | failure = e; | |
463 | } | |
464 | mySp i = nextSp i(mySpi, f alse); | |
465 | } | |
466 | } while (myS pi != null ); | |
467 | if (failure instanceof InvalidAl gorithmPar ameterExce ption) { | |
468 | throw (I nvalidAlgo rithmParam eterExcept ion)failur e; | |
469 | } | |
470 | if (failure instanceof RuntimeEx ception) { | |
471 | throw (R untimeExce ption)fail ure; | |
472 | } | |
473 | th row new In validAlgor ithmParame terExcepti on("init() failed", failure); | |
474 | } | |
475 | ||
476 | /** | |
477 | * Ini tializes t his key ge nerator fo r a certai n keysize. | |
478 | * | |
479 | * <p> If this k ey generat or require s any rand om bytes, it will ge t them | |
480 | * usi ng the | |
481 | * {@l ink java.s ecurity.Se cureRandom } | |
482 | * imp lementatio n of the h ighest-pri ority inst alled | |
483 | * pro vider as t he source of randomn ess. | |
484 | * (If none of t he install ed provide rs supply an impleme ntation of | |
485 | * Sec ureRandom, a system- provided s ource of r andomness will be us ed.) | |
486 | * | |
487 | * @pa ram keysiz e the keys ize. This is an algo rithm-spec ific metri c, | |
488 | * spe cified in number of bits. | |
489 | * | |
490 | * @ex ception In validParam eterExcept ion if the keysize i s wrong or not | |
491 | * sup ported. | |
492 | */ | |
493 | public final voi d init(int keysize) { | |
494 | in it(keysize , JceSecur ity.RANDOM ); | |
495 | } | |
496 | ||
497 | /** | |
498 | * Ini tializes t his key ge nerator fo r a certai n keysize, using a | |
499 | * use r-provided source of randomnes s. | |
500 | * | |
501 | * @pa ram keysiz e the keys ize. This is an algo rithm-spec ific metri c, | |
502 | * spe cified in number of bits. | |
503 | * @pa ram random the sourc e of rando mness for this key g enerator | |
504 | * | |
505 | * @ex ception In validParam eterExcept ion if the keysize i s wrong or not | |
506 | * sup ported. | |
507 | */ | |
508 | public final voi d init(int keysize, SecureRand om random) { | |
509 | if (serviceI terator == null) { | |
510 | spi.engi neInit(key size, rand om); | |
511 | return; | |
512 | } | |
513 | Ru ntimeExcep tion failu re = null; | |
514 | Ke yGenerator Spi mySpi = spi; | |
515 | do { | |
516 | try { | |
517 | mySp i.engineIn it(keysize , random); | |
518 | init Type = I_S IZE; | |
519 | init KeySize = keysize; | |
520 | init Params = n ull; | |
521 | init Random = r andom; | |
522 | retu rn; | |
523 | } catch (RuntimeEx ception e) { | |
524 | if ( failure == null) { | |
525 | failure = e; | |
526 | } | |
527 | mySp i = nextSp i(mySpi, f alse); | |
528 | } | |
529 | } while (myS pi != null ); | |
530 | th row failur e; | |
531 | } | |
532 | ||
533 | /** | |
534 | * Generate s a PW key. | |
535 | * | |
536 | * @re turn the n ew key | |
537 | */ | |
538 | public final Sec retKey gen erateKey() { | |
539 | if (serviceI terator == null) { | |
540 | return s pi.engineG enerateKey (); | |
541 | } | |
542 | Ru ntimeExcep tion failu re = null; | |
543 | Ke yGenerator Spi mySpi = spi; | |
544 | do { | |
545 | try { | |
546 | retu rn mySpi.e ngineGener ateKey(); | |
547 | } catch (RuntimeEx ception e) { | |
548 | if ( failure == null) { | |
549 | failure = e; | |
550 | } | |
551 | mySp i = nextSp i(mySpi, t rue); | |
552 | } | |
553 | } while (myS pi != null ); | |
554 | th row failur e; | |
555 | } | |
556 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.