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 | SecretKeyFactory.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 | SecretKeyFactory.java | Wed Sep 12 17:18:39 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 19 | 822 |
Changed | 18 | 36 |
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, 2011, 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 | ||
37 | /** | |
38 | * This cl ass repres ents a fac tory for PW keys. | |
39 | * | |
40 | * <P> Key factories are used to convert <I>keys</ I> (opaque | |
41 | * cryptog raphic key s of type <code>Key< /code>) in to <I>key specificat ions</I> | |
42 | * (transp arent repr esentation s of the u nderlying key materi al), and v ice | |
43 | * versa. | |
44 | * Secret key factor ies operat e only on PW (symmetric ) keys. | |
45 | * | |
46 | * <P> Key factories are bi-di rectional, i.e., the y allow to build an opaque | |
47 | * key obj ect from a given key specifica tion (key material), or to ret rieve | |
48 | * the und erlying ke y material of a key object in a suitable format. | |
49 | * | |
50 | * <P> App lication d evelopers should ref er to thei r provider 's documen tation | |
51 | * to find out which key speci fications are suppor ted by the | |
52 | * {@link #generateS ecret(java .security. spec.KeySp ec) genera teSecret} and | |
53 | * {@link #getKeySpe c(javax.cr ypto.Secre tKey, java .lang.Clas s) getKeyS pec} | |
54 | * methods . | |
55 | * For exa mple, the DES PW -key facto ry supplie d by the " SunJCE" pr ovider | |
56 | * support s <code>DE SKeySpec</ code> as a transpare nt represe ntation of DES | |
57 | * keys, a nd that pr ovider's PW -key facto ry for Tri ple DES ke ys support s | |
58 | * <code>D ESedeKeySp ec</code> as a trans parent rep resentatio n of Tripl e DES | |
59 | * keys. | |
60 | * | |
61 | * <p> Eve ry impleme ntation of the Java platform i s required to suppor t the | |
62 | * followi ng standar d <code>Se cretKeyFac tory</code > algorith ms: | |
63 | * <ul> | |
64 | * <li><tt >DES</tt>< /li> | |
65 | * <li><tt >DESede</t t></li> | |
66 | * </ul> | |
67 | * These a lgorithms are descri bed in the <a href= | |
68 | * "{@docR oot}/../te chnotes/gu ides/secur ity/Standa rdNames.ht ml#SecretK eyFactory" > | |
69 | * SecretK eyFactory section</a > of the | |
70 | * Java Cr yptography Architect ure Standa rd Algorit hm Name Do cumentatio n. | |
71 | * Consult the relea se documen tation for your impl ementation to see if any | |
72 | * other a lgorithms are suppor ted. | |
73 | * | |
74 | * @author Jan Luehe | |
75 | * | |
76 | * @see Se cretKey | |
77 | * @see ja vax.crypto .spec.DESK eySpec | |
78 | * @see ja vax.crypto .spec.DESe deKeySpec | |
79 | * @see ja vax.crypto .spec.PBEK eySpec | |
80 | * @since 1.4 | |
81 | */ | |
82 | ||
83 | public cla ss SecretK eyFactory { | |
84 | ||
85 | // The provider | |
86 | privat e Provider provider; | |
87 | ||
88 | // The algorithm associate d with thi s factory | |
89 | privat e final St ring algor ithm; | |
90 | ||
91 | // The provider implementa tion (dele gate) | |
92 | privat e volatile SecretKey FactorySpi spi; | |
93 | ||
94 | // loc k for mute x during p rovider se lection | |
95 | privat e final Ob ject lock = new Obje ct(); | |
96 | ||
97 | // rem aining ser vices to t ry in prov ider selec tion | |
98 | // nul l once pro vider is s elected | |
99 | privat e Iterator <Service> serviceIte rator; | |
100 | ||
101 | /** | |
102 | * Cre ates a Sec retKeyFact ory object . | |
103 | * | |
104 | * @pa ram keyFac Spi the de legate | |
105 | * @pa ram provid er the pro vider | |
106 | * @param a lgorithm t he PW -key algor ithm | |
107 | */ | |
108 | protec ted Secret KeyFactory (SecretKey FactorySpi keyFacSpi , | |
109 | Provider provider, String alg orithm) { | |
110 | th is.spi = k eyFacSpi; | |
111 | th is.provide r = provid er; | |
112 | th is.algorit hm = algor ithm; | |
113 | } | |
114 | ||
115 | privat e SecretKe yFactory(S tring algo rithm) thr ows NoSuch AlgorithmE xception { | |
116 | th is.algorit hm = algor ithm; | |
117 | Li st<Service > list = | |
118 | GetI nstance.ge tServices( "SecretKey Factory", algorithm) ; | |
119 | se rviceItera tor = list .iterator( ); | |
120 | // fetch and instantia te initial spi | |
121 | if (nextSpi( null) == n ull) { | |
122 | throw ne w NoSuchAl gorithmExc eption | |
123 | (alg orithm + " SecretKey Factory no t availabl e"); | |
124 | } | |
125 | } | |
126 | ||
127 | /** | |
128 | * Ret urns a <co de>SecretK eyFactory< /code> obj ect that c onverts | |
129 | * PW keys of th e specifie d algorith m. | |
130 | * | |
131 | * <p> This meth od travers es the lis t of regis tered secu rity Provi ders, | |
132 | * sta rting with the most preferred Provider. | |
133 | * A n ew SecretK eyFactory object enc apsulating the | |
134 | * Sec retKeyFact orySpi imp lementatio n from the first | |
135 | * Pro vider that supports the specif ied algori thm is ret urned. | |
136 | * | |
137 | * <p> Note that the list of registe red provid ers may be retrieved via | |
138 | * the {@link Se curity#get Providers( ) Security .getProvid ers()} met hod. | |
139 | * | |
140 | * @param a lgorithm t he standar d name of the reques ted PW -key | |
141 | * alg orithm. | |
142 | * See the Secre tKeyFactor y section in the <a href= | |
143 | * "{@ docRoot}/. ./technote s/guides/s ecurity/St andardName s.html#Sec retKeyFact ory"> | |
144 | * Jav a Cryptogr aphy Archi tecture St andard Alg orithm Nam e Document ation</a> | |
145 | * for informati on about s tandard al gorithm na mes. | |
146 | * | |
147 | * @re turn the n ew <code>S ecretKeyFa ctory</cod e> object. | |
148 | * | |
149 | * @ex ception Nu llPointerE xception i f the spec ified algo rithm | |
150 | * is n ull. | |
151 | * | |
152 | * @ex ception No SuchAlgori thmExcepti on if no P rovider su pports a | |
153 | * Secr etKeyFacto rySpi impl ementation for the | |
154 | * spec ified algo rithm. | |
155 | * | |
156 | * @se e java.sec urity.Prov ider | |
157 | */ | |
158 | public static fi nal Secret KeyFactory getInstan ce(String algorithm) | |
159 | throws N oSuchAlgor ithmExcept ion { | |
160 | re turn new S ecretKeyFa ctory(algo rithm); | |
161 | } | |
162 | ||
163 | /** | |
164 | * Ret urns a <co de>SecretK eyFactory< /code> obj ect that c onverts | |
165 | * PW keys of th e specifie d algorith m. | |
166 | * | |
167 | * <p> A new Sec retKeyFact ory object encapsula ting the | |
168 | * Sec retKeyFact orySpi imp lementatio n from the specified provider | |
169 | * is returned. The speci fied provi der must b e register ed | |
170 | * in the securi ty provide r list. | |
171 | * | |
172 | * <p> Note that the list of registe red provid ers may be retrieved via | |
173 | * the {@link Se curity#get Providers( ) Security .getProvid ers()} met hod. | |
174 | * | |
175 | * @param a lgorithm t he standar d name of the reques ted PW -key | |
176 | * alg orithm. | |
177 | * See the Secre tKeyFactor y section in the <a href= | |
178 | * "{@ docRoot}/. ./technote s/guides/s ecurity/St andardName s.html#Sec retKeyFact ory"> | |
179 | * Jav a Cryptogr aphy Archi tecture St andard Alg orithm Nam e Document ation</a> | |
180 | * for informati on about s tandard al gorithm na mes. | |
181 | * | |
182 | * @pa ram provid er the nam e of the p rovider. | |
183 | * | |
184 | * @re turn the n ew <code>S ecretKeyFa ctory</cod e> object. | |
185 | * | |
186 | * @ex ception No SuchAlgori thmExcepti on if a Se cretKeyFac torySpi | |
187 | * impl ementation for the s pecified a lgorithm i s not | |
188 | * avai lable from the speci fied provi der. | |
189 | * | |
190 | * @ex ception Nu llPointerE xception i f the spec ified algo rithm | |
191 | * is n ull. | |
192 | * | |
193 | * @th rows NoSuc hProviderE xception i f the spec ified prov ider is no t | |
194 | * regi stered in the securi ty provide r list. | |
195 | * | |
196 | * @ex ception Il legalArgum entExcepti on if the <code>prov ider</code > | |
197 | * is n ull or emp ty. | |
198 | * | |
199 | * @se e java.sec urity.Prov ider | |
200 | */ | |
201 | public static fi nal Secret KeyFactory getInstan ce(String algorithm, | |
202 | String p rovider) t hrows NoSu chAlgorith mException , | |
203 | NoSuchPr oviderExce ption { | |
204 | In stance ins tance = Jc eSecurity. getInstanc e("SecretK eyFactory" , | |
205 | Secr etKeyFacto rySpi.clas s, algorit hm, provid er); | |
206 | re turn new S ecretKeyFa ctory((Sec retKeyFact orySpi)ins tance.impl , | |
207 | inst ance.provi der, algor ithm); | |
208 | } | |
209 | ||
210 | /** | |
211 | * Ret urns a <co de>SecretK eyFactory< /code> obj ect that c onverts | |
212 | * PW keys of th e specifie d algorith m. | |
213 | * | |
214 | * <p> A new Sec retKeyFact ory object encapsula ting the | |
215 | * Sec retKeyFact orySpi imp lementatio n from the specified Provider | |
216 | * obj ect is ret urned. No te that th e specifie d Provider object | |
217 | * doe s not have to be reg istered in the provi der list. | |
218 | * | |
219 | * @param a lgorithm t he standar d name of the reques ted PW -key | |
220 | * alg orithm. | |
221 | * See the Secre tKeyFactor y section in the <a href= | |
222 | * "{@ docRoot}/. ./technote s/guides/s ecurity/St andardName s.html#Sec retKeyFact ory"> | |
223 | * Jav a Cryptogr aphy Archi tecture St andard Alg orithm Nam e Document ation</a> | |
224 | * for informati on about s tandard al gorithm na mes. | |
225 | * | |
226 | * @pa ram provid er the pro vider. | |
227 | * | |
228 | * @re turn the n ew <code>S ecretKeyFa ctory</cod e> object. | |
229 | * | |
230 | * @ex ception Nu llPointerE xception i f the spec ified algo rithm | |
231 | * is null. | |
232 | * | |
233 | * @ex ception No SuchAlgori thmExcepti on if a Se cretKeyFac torySpi | |
234 | * impl ementation for the s pecified a lgorithm i s not avai lable | |
235 | * from the speci fied Provi der object . | |
236 | * | |
237 | * @ex ception Il legalArgum entExcepti on if the <code>prov ider</code > | |
238 | * is n ull. | |
239 | * | |
240 | * @se e java.sec urity.Prov ider | |
241 | */ | |
242 | public static fi nal Secret KeyFactory getInstan ce(String algorithm, | |
243 | Provider provider) throws No SuchAlgori thmExcepti on { | |
244 | In stance ins tance = Jc eSecurity. getInstanc e("SecretK eyFactory" , | |
245 | Secr etKeyFacto rySpi.clas s, algorit hm, provid er); | |
246 | re turn new S ecretKeyFa ctory((Sec retKeyFact orySpi)ins tance.impl , | |
247 | inst ance.provi der, algor ithm); | |
248 | } | |
249 | ||
250 | /** | |
251 | * Ret urns the p rovider of this <cod e>SecretKe yFactory</ code> obje ct. | |
252 | * | |
253 | * @re turn the p rovider of this <cod e>SecretKe yFactory</ code> obje ct | |
254 | */ | |
255 | public final Pro vider getP rovider() { | |
256 | sy nchronized (lock) { | |
257 | // disab le further failover after this call | |
258 | serviceI terator = null; | |
259 | return p rovider; | |
260 | } | |
261 | } | |
262 | ||
263 | /** | |
264 | * Ret urns the a lgorithm n ame of thi s <code>Se cretKeyFac tory</code > object. | |
265 | * | |
266 | * <p> This is th e same nam e that was specified in one of the | |
267 | * <co de>getInst ance</code > calls th at created this | |
268 | * <co de>SecretK eyFactory< /code> obj ect. | |
269 | * | |
270 | * @re turn the a lgorithm n ame of thi s <code>Se cretKeyFac tory</code > | |
271 | * obj ect. | |
272 | */ | |
273 | public final Str ing getAlg orithm() { | |
274 | re turn this. algorithm; | |
275 | } | |
276 | ||
277 | /** | |
278 | * Upd ate the ac tive spi o f this cla ss and ret urn the ne xt | |
279 | * imp lementatio n for fail over. If n o more imp lemenation s are | |
280 | * ava ilable, th is method returns nu ll. Howeve r, the act ive spi of | |
281 | * thi s class is never set to null. | |
282 | */ | |
283 | privat e SecretKe yFactorySp i nextSpi( SecretKeyF actorySpi oldSpi) { | |
284 | sy nchronized (lock) { | |
285 | // someb ody else d id a failo ver concur rently | |
286 | // try t hat spi no w | |
287 | if ((old Spi != nul l) && (old Spi != spi )) { | |
288 | retu rn spi; | |
289 | } | |
290 | if (serv iceIterato r == null) { | |
291 | retu rn null; | |
292 | } | |
293 | while (s erviceIter ator.hasNe xt()) { | |
294 | Serv ice s = se rviceItera tor.next() ; | |
295 | if ( JceSecurit y.canUsePr ovider(s.g etProvider ()) == fal se) { | |
296 | continue; | |
297 | } | |
298 | try { | |
299 | Object obj = s.newIn stance(nul l); | |
300 | if (obj in stanceof S ecretKeyFa ctorySpi = = false) { | |
301 | contin ue; | |
302 | } | |
303 | SecretKeyF actorySpi spi = (Sec retKeyFact orySpi)obj ; | |
304 | provider = s.getProv ider(); | |
305 | this.spi = spi; | |
306 | return spi ; | |
307 | } ca tch (NoSuc hAlgorithm Exception e) { | |
308 | // ignore | |
309 | } | |
310 | } | |
311 | serviceI terator = null; | |
312 | return n ull; | |
313 | } | |
314 | } | |
315 | ||
316 | /** | |
317 | * Gen erates a < code>Secre tKey</code > object f rom the pr ovided key | |
318 | * spe cification (key mate rial). | |
319 | * | |
320 | * @param k eySpec the specifica tion (key material) of the PW key | |
321 | * | |
322 | * @return the PW key | |
323 | * | |
324 | * @ex ception In validKeySp ecExceptio n if the g iven key s pecificati on | |
325 | * is inapp ropriate f or this PW -key facto ry to prod uce a PW key. | |
326 | */ | |
327 | public final Sec retKey gen erateSecre t(KeySpec keySpec) | |
328 | throws I nvalidKeyS pecExcepti on { | |
329 | if (serviceI terator == null) { | |
330 | return s pi.engineG enerateSec ret(keySpe c); | |
331 | } | |
332 | Ex ception fa ilure = nu ll; | |
333 | Se cretKeyFac torySpi my Spi = spi; | |
334 | do { | |
335 | try { | |
336 | retu rn mySpi.e ngineGener ateSecret( keySpec); | |
337 | } catch (Exception e) { | |
338 | if ( failure == null) { | |
339 | failure = e; | |
340 | } | |
341 | mySp i = nextSp i(mySpi); | |
342 | } | |
343 | } while (myS pi != null ); | |
344 | if (failure instanceof InvalidKe ySpecExcep tion) { | |
345 | throw (I nvalidKeyS pecExcepti on)failure ; | |
346 | } | |
347 | th row new In validKeySp ecExceptio n | |
348 | ("Could no t generate PW key", fail ure); | |
349 | } | |
350 | ||
351 | /** | |
352 | * Ret urns a spe cification (key mate rial) of t he given k ey object | |
353 | * in the reques ted format . | |
354 | * | |
355 | * @pa ram key th e key | |
356 | * @pa ram keySpe c the requ ested form at in whic h the key material s hall be | |
357 | * ret urned | |
358 | * | |
359 | * @re turn the u nderlying key specif ication (k ey materia l) in the | |
360 | * req uested for mat | |
361 | * | |
362 | * @ex ception In validKeySp ecExceptio n if the r equested k ey specifi cation is | |
363 | * ina ppropriate for the g iven key ( e.g., the algorithms associate d with | |
364 | * <co de>key</co de> and <c ode>keySpe c</code> d o not matc h, or | |
365 | * <co de>key</co de> refere nces a key on a cryp tographic hardware d evice | |
366 | * whe reas <code >keySpec</ code> is t he specifi cation of a software -based | |
367 | * key ), or the given key cannot be dealt with | |
368 | * (e. g., the gi ven key ha s an algor ithm or fo rmat not s upported b y this | |
369 | * PW -key facto ry). | |
370 | */ | |
371 | public final Key Spec getKe ySpec(Secr etKey key, Class<?> keySpec) | |
372 | throws I nvalidKeyS pecExcepti on { | |
373 | if (serviceI terator == null) { | |
374 | return s pi.engineG etKeySpec( key, keySp ec); | |
375 | } | |
376 | Ex ception fa ilure = nu ll; | |
377 | Se cretKeyFac torySpi my Spi = spi; | |
378 | do { | |
379 | try { | |
380 | retu rn mySpi.e ngineGetKe ySpec(key, keySpec); | |
381 | } catch (Exception e) { | |
382 | if ( failure == null) { | |
383 | failure = e; | |
384 | } | |
385 | mySp i = nextSp i(mySpi); | |
386 | } | |
387 | } while (myS pi != null ); | |
388 | if (failure instanceof InvalidKe ySpecExcep tion) { | |
389 | throw (I nvalidKeyS pecExcepti on)failure ; | |
390 | } | |
391 | th row new In validKeySp ecExceptio n | |
392 | ("Co uld not ge t key spec ", failure ); | |
393 | } | |
394 | ||
395 | /** | |
396 | * Tra nslates a key object , whose pr ovider may be unknow n or poten tially | |
397 | * untruste d, into a correspond ing key ob ject of th is PW -key facto ry. | |
398 | * | |
399 | * @pa ram key th e key whos e provider is unknow n or untru sted | |
400 | * | |
401 | * @re turn the t ranslated key | |
402 | * | |
403 | * @ex ception In validKeyEx ception if the given key canno t be proce ssed | |
404 | * by this PW -key facto ry. | |
405 | */ | |
406 | public final Sec retKey tra nslateKey( SecretKey key) | |
407 | throws I nvalidKeyE xception { | |
408 | if (serviceI terator == null) { | |
409 | return s pi.engineT ranslateKe y(key); | |
410 | } | |
411 | Ex ception fa ilure = nu ll; | |
412 | Se cretKeyFac torySpi my Spi = spi; | |
413 | do { | |
414 | try { | |
415 | retu rn mySpi.e ngineTrans lateKey(ke y); | |
416 | } catch (Exception e) { | |
417 | if ( failure == null) { | |
418 | failure = e; | |
419 | } | |
420 | mySp i = nextSp i(mySpi); | |
421 | } | |
422 | } while (myS pi != null ); | |
423 | if (failure instanceof InvalidKe yException ) { | |
424 | throw (I nvalidKeyE xception)f ailure; | |
425 | } | |
426 | th row new In validKeyEx ception | |
427 | ("Co uld not tr anslate ke y", failur e); | |
428 | } | |
429 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.