Produced by Araxis Merge on 9/25/2018 2:13:01 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\com\sun\crypto\provider | DESedeCipher.java | Mon Jan 22 14:46:50 2018 UTC |
2 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\com\sun\crypto\provider | DESedeCipher.java | Wed Sep 12 16:22:22 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 850 |
Changed | 1 | 2 |
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, 2010, 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 co m.sun.cryp to.provide r; | |
27 | ||
28 | import jav a.security .*; | |
29 | import jav a.security .spec.*; | |
30 | import jav ax.crypto. *; | |
31 | import jav ax.crypto. spec.*; | |
32 | ||
33 | /** | |
34 | * This cl ass implem ents the D ESede algo rithm (DES -EDE, trip leDES) in | |
35 | * its var ious modes (<code>EC B</code>, <code>CFB< /code>, <c ode>OFB</c ode>, | |
36 | * <code>C BC</code>, <code>PCB C</code>) and paddin g schemes | |
37 | * (<code> PKCS5Paddi ng</code>, <code>NoP adding</co de>, | |
38 | * <code>I SO10126Pad ding</code >). | |
39 | * | |
40 | * @author Gigi Anke ny | |
41 | * | |
42 | * | |
43 | * @see DE SCipher | |
44 | */ | |
45 | ||
46 | public fin al class D ESedeCiphe r extends CipherSpi { | |
47 | ||
48 | /* | |
49 | * int ernal Ciph erCore obj ect which does the r eal work. | |
50 | */ | |
51 | privat e CipherCo re core = null; | |
52 | ||
53 | /** | |
54 | * Cre ates an in stance of DESede cip her with d efault ECB mode and | |
55 | * PKC S5Padding. | |
56 | */ | |
57 | public DESedeCip her() { | |
58 | co re = new C ipherCore( new DESede Crypt(), D ESConstant s.DES_BLOC K_SIZE); | |
59 | } | |
60 | ||
61 | /** | |
62 | * Set s the mode of this c ipher. | |
63 | * | |
64 | * @pa ram mode t he cipher mode | |
65 | * | |
66 | * @ex ception No SuchAlgori thmExcepti on if the requested cipher mod e does | |
67 | * not exist | |
68 | */ | |
69 | protec ted void e ngineSetMo de(String mode) | |
70 | th rows NoSuc hAlgorithm Exception { | |
71 | co re.setMode (mode); | |
72 | } | |
73 | ||
74 | /** | |
75 | * Set s the padd ing mechan ism of thi s cipher. | |
76 | * | |
77 | * @pa ram paddin g the padd ing mechan ism | |
78 | * | |
79 | * @ex ception No SuchPaddin gException if the re quested pa dding mech anism | |
80 | * doe s not exis t | |
81 | */ | |
82 | protec ted void e ngineSetPa dding(Stri ng padding Scheme) | |
83 | th rows NoSuc hPaddingEx ception { | |
84 | co re.setPadd ing(paddin gScheme); | |
85 | } | |
86 | ||
87 | /** | |
88 | * Ret urns the b lock size (in bytes) . | |
89 | * | |
90 | * @re turn the b lock size (in bytes) , or 0 if the underl ying algor ithm is | |
91 | * not a block c ipher | |
92 | */ | |
93 | protec ted int en gineGetBlo ckSize() { | |
94 | re turn DESCo nstants.DE S_BLOCK_SI ZE; | |
95 | } | |
96 | ||
97 | /** | |
98 | * Ret urns the l ength in b ytes that an output buffer wou ld need to be in | |
99 | * ord er to hold the resul t of the n ext <code> update</co de> or | |
100 | * <co de>doFinal </code> op eration, g iven the i nput lengt h | |
101 | * <co de>inputLe n</code> ( in bytes). | |
102 | * | |
103 | * <p> This call takes into account a ny unproce ssed (buff ered) data from a | |
104 | * pre vious <cod e>update</ code> call , and padd ing. | |
105 | * | |
106 | * <p> The actual output le ngth of th e next <co de>update< /code> or | |
107 | * <co de>doFinal </code> ca ll may be smaller th an the len gth return ed by | |
108 | * thi s method. | |
109 | * | |
110 | * @pa ram inputL en the inp ut length (in bytes) | |
111 | * | |
112 | * @re turn the r equired ou tput buffe r size (in bytes) | |
113 | */ | |
114 | protec ted int en gineGetOut putSize(in t inputLen ) { | |
115 | re turn core. getOutputS ize(inputL en); | |
116 | } | |
117 | ||
118 | /** | |
119 | * Ret urns the i nitializat ion vector (IV) in a new buffe r. | |
120 | * | |
121 | * <p> This is us eful in th e case whe re a rando m IV has b een create d | |
122 | * (se e <a href = "#init"> init</a>), | |
123 | * or in the con text of pa ssword-bas ed encrypt ion or | |
124 | * dec ryption, w here the I V is deriv ed from a user-provi ded passwo rd. | |
125 | * | |
126 | * @re turn the i nitializat ion vector in a new buffer, or null if t he | |
127 | * und erlying al gorithm do es not use an IV, or if the IV has not y et | |
128 | * bee n set. | |
129 | */ | |
130 | protec ted byte[] engineGet IV() { | |
131 | re turn core. getIV(); | |
132 | } | |
133 | ||
134 | /** | |
135 | * Ini tializes t his cipher with a ke y and a so urce of ra ndomness. | |
136 | * | |
137 | * <p> The cipher is initia lized for one of the following four oper ations: | |
138 | * enc ryption, d ecryption, key wrapp ing or key unwrappin g, dependi ng on | |
139 | * the value of <code>opmo de</code>. | |
140 | * | |
141 | * <p> If this ci pher requi res an ini tializatio n vector ( IV), it wi ll get | |
142 | * it from <code >random</c ode>. | |
143 | * Thi s behaviou r should o nly be use d in encry ption or k ey wrappin g | |
144 | * mod e, however . | |
145 | * Whe n initiali zing a cip her that r equires an IV for de cryption o r | |
146 | * key unwrappin g, the IV | |
147 | * (sa me IV that was used for encryp tion or ke y wrapping ) must be provided | |
148 | * exp licitly as a | |
149 | * par ameter, in order to get the co rrect resu lt. | |
150 | * | |
151 | * <p> This metho d also cle ans existi ng buffer and other related st ate | |
152 | * inf ormation. | |
153 | * | |
154 | * @pa ram opmode the opera tion mode of this ci pher (this is one of | |
155 | * the following : | |
156 | * <co de>ENCRYPT _MODE</cod e>, <code> DECRYPT_MO DE</code>, | |
157 | * <co de>WRAP_MO DE</code> or <code>U NWRAP_MODE </code>) | |
158 | * @param k ey the PW key | |
159 | * @pa ram random the sourc e of rando mness | |
160 | * | |
161 | * @ex ception In validKeyEx ception if the given key is in appropriat e for | |
162 | * ini tializing this ciphe r | |
163 | */ | |
164 | protec ted void e ngineInit( int opmode , Key key, SecureRan dom random ) | |
165 | th rows Inval idKeyExcep tion { | |
166 | co re.init(op mode, key, random); | |
167 | } | |
168 | ||
169 | /** | |
170 | * Ini tializes t his cipher with a ke y, a set o f | |
171 | * alg orithm par ameters, a nd a sourc e of rando mness. | |
172 | * | |
173 | * <p> The cipher is initia lized for one of the following four oper ations: | |
174 | * enc ryption, d ecryption, key wrapp ing or key unwrappin g, dependi ng on | |
175 | * the value of <code>opmo de</code>. | |
176 | * | |
177 | * <p> If this ci pher (incl uding its underlying feedback or padding scheme) | |
178 | * req uires any random byt es, it wil l get them from <cod e>random</ code>. | |
179 | * | |
180 | * @pa ram opmode the opera tion mode of this ci pher (this is one of | |
181 | * the following : | |
182 | * <co de>ENCRYPT _MODE</cod e>, <code> DECRYPT_MO DE</code>, | |
183 | * <co de>WRAP_MO DE</code> or <code>U NWRAP_MODE </code>) | |
184 | * @pa ram key th e encrypti on key | |
185 | * @pa ram params the algor ithm param eters | |
186 | * @pa ram random the sourc e of rando mness | |
187 | * | |
188 | * @ex ception In validKeyEx ception if the given key is in appropriat e for | |
189 | * ini tializing this ciphe r | |
190 | * @ex ception In validAlgor ithmParame terExcepti on if the given algo rithm | |
191 | * par ameters ar e inapprop riate for this ciphe r | |
192 | */ | |
193 | protec ted void e ngineInit( int opmode , Key key, | |
194 | AlgorithmP arameterSp ec params, | |
195 | SecureRand om random) | |
196 | th rows Inval idKeyExcep tion, Inva lidAlgorit hmParamete rException { | |
197 | co re.init(op mode, key, params, r andom); | |
198 | } | |
199 | ||
200 | protec ted void e ngineInit( int opmode , Key key, | |
201 | AlgorithmP arameters params, | |
202 | SecureRand om random) | |
203 | th rows Inval idKeyExcep tion, Inva lidAlgorit hmParamete rException { | |
204 | co re.init(op mode, key, params, r andom); | |
205 | } | |
206 | ||
207 | /** | |
208 | * Con tinues a m ultiple-pa rt encrypt ion or dec ryption op eration | |
209 | * (de pending on how this cipher was initializ ed), proce ssing anot her data | |
210 | * par t. | |
211 | * | |
212 | * <p> The first <code>inpu tLen</code > bytes in the <code >input</co de> | |
213 | * buf fer, start ing at <co de>inputOf fset</code >, are pro cessed, an d the | |
214 | * res ult is sto red in a n ew buffer. | |
215 | * | |
216 | * @pa ram input the input buffer | |
217 | * @pa ram inputO ffset the offset in <code>inpu t</code> w here the i nput | |
218 | * sta rts | |
219 | * @pa ram inputL en the inp ut length | |
220 | * | |
221 | * @re turn the n ew buffer with the r esult | |
222 | * | |
223 | * @ex ception Il legalState Exception if this ci pher is in a wrong s tate | |
224 | * (e. g., has no t been ini tialized) | |
225 | */ | |
226 | protec ted byte[] engineUpd ate(byte[] input, in t inputOff set, | |
227 | int in putLen) { | |
228 | re turn core. update(inp ut, inputO ffset, inp utLen); | |
229 | } | |
230 | ||
231 | /** | |
232 | * Con tinues a m ultiple-pa rt encrypt ion or dec ryption op eration | |
233 | * (de pending on how this cipher was initializ ed), proce ssing anot her data | |
234 | * par t. | |
235 | * | |
236 | * <p> The first <code>inpu tLen</code > bytes in the <code >input</co de> | |
237 | * buf fer, start ing at <co de>inputOf fset</code >, are pro cessed, an d the | |
238 | * res ult is sto red in the <code>out put</code> buffer, s tarting at | |
239 | * <co de>outputO ffset</cod e>. | |
240 | * | |
241 | * @pa ram input the input buffer | |
242 | * @pa ram inputO ffset the offset in <code>inpu t</code> w here the i nput | |
243 | * sta rts | |
244 | * @pa ram inputL en the inp ut length | |
245 | * @pa ram output the buffe r for the result | |
246 | * @pa ram output Offset the offset in <code>out put</code> where the result | |
247 | * is stored | |
248 | * | |
249 | * @re turn the n umber of b ytes store d in <code >output</c ode> | |
250 | * | |
251 | * @ex ception Sh ortBufferE xception i f the give n output b uffer is t oo small | |
252 | * to hold the r esult | |
253 | */ | |
254 | protec ted int en gineUpdate (byte[] in put, int i nputOffset , int inpu tLen, | |
255 | byte[] ou tput, int outputOffs et) | |
256 | th rows Short BufferExce ption { | |
257 | re turn core. update(inp ut, inputO ffset, inp utLen, out put, | |
258 | out putOffset) ; | |
259 | } | |
260 | ||
261 | /** | |
262 | * Enc rypts or d ecrypts da ta in a si ngle-part operation, | |
263 | * or finishes a multiple- part opera tion. | |
264 | * The data is e ncrypted o r decrypte d, dependi ng on how this ciphe r was | |
265 | * ini tialized. | |
266 | * | |
267 | * <p> The first <code>inpu tLen</code > bytes in the <code >input</co de> | |
268 | * buf fer, start ing at <co de>inputOf fset</code >, and any input byt es that | |
269 | * may have been buffered during a p revious <c ode>update </code> op eration, | |
270 | * are processed , with pad ding (if r equested) being appl ied. | |
271 | * The result is stored in a new buf fer. | |
272 | * | |
273 | * <p> The cipher is reset to its ini tial state (uninitia lized) aft er this | |
274 | * cal l. | |
275 | * | |
276 | * @pa ram input the input buffer | |
277 | * @pa ram inputO ffset the offset in <code>inpu t</code> w here the i nput | |
278 | * sta rts | |
279 | * @pa ram inputL en the inp ut length | |
280 | * | |
281 | * @re turn the n ew buffer with the r esult | |
282 | * | |
283 | * @ex ception Il legalBlock SizeExcept ion if thi s cipher i s a block cipher, | |
284 | * no padding ha s been req uested (on ly in encr yption mod e), and th e total | |
285 | * inp ut length of the dat a processe d by this cipher is not a mult iple of | |
286 | * blo ck size | |
287 | * @ex ception Ba dPaddingEx ception if this ciph er is in d ecryption mode, | |
288 | * and (un)paddi ng has bee n requeste d, but the decrypted data is n ot | |
289 | * bou nded by th e appropri ate paddin g bytes | |
290 | */ | |
291 | protec ted byte[] engineDoF inal(byte[ ] input, i nt inputOf fset, | |
292 | int i nputLen) | |
293 | th rows Illeg alBlockSiz eException , BadPaddi ngExceptio n { | |
294 | re turn core. doFinal(in put, input Offset, in putLen); | |
295 | } | |
296 | ||
297 | /** | |
298 | * Enc rypts or d ecrypts da ta in a si ngle-part operation, | |
299 | * or finishes a multiple- part opera tion. | |
300 | * The data is e ncrypted o r decrypte d, dependi ng on how this ciphe r was | |
301 | * ini tialized. | |
302 | * | |
303 | * <p> The first <code>inpu tLen</code > bytes in the <code >input</co de> | |
304 | * buf fer, start ing at <co de>inputOf fset</code >, and any input byt es that | |
305 | * may have been buffered during a p revious <c ode>update </code> op eration, | |
306 | * are processed , with pad ding (if r equested) being appl ied. | |
307 | * The result is stored in the <code >output</c ode> buffe r, startin g at | |
308 | * <co de>outputO ffset</cod e>. | |
309 | * | |
310 | * <p> The cipher is reset to its ini tial state (uninitia lized) aft er this | |
311 | * cal l. | |
312 | * | |
313 | * @pa ram input the input buffer | |
314 | * @pa ram inputO ffset the offset in <code>inpu t</code> w here the i nput | |
315 | * sta rts | |
316 | * @pa ram inputL en the inp ut length | |
317 | * @pa ram output the buffe r for the result | |
318 | * @pa ram output Offset the offset in <code>out put</code> where the result | |
319 | * is stored | |
320 | * | |
321 | * @re turn the n umber of b ytes store d in <code >output</c ode> | |
322 | * | |
323 | * @ex ception Il legalBlock SizeExcept ion if thi s cipher i s a block cipher, | |
324 | * no padding ha s been req uested (on ly in encr yption mod e), and th e total | |
325 | * inp ut length of the dat a processe d by this cipher is not a mult iple of | |
326 | * blo ck size | |
327 | * @ex ception Sh ortBufferE xception i f the give n output b uffer is t oo small | |
328 | * to hold the r esult | |
329 | * @ex ception Ba dPaddingEx ception if this ciph er is in d ecryption mode, | |
330 | * and (un)paddi ng has bee n requeste d, but the decrypted data is n ot | |
331 | * bou nded by th e appropri ate paddin g bytes | |
332 | */ | |
333 | protec ted int en gineDoFina l(byte[] i nput, int inputOffse t, int inp utLen, | |
334 | byte[] o utput, int outputOff set) | |
335 | th rows Illeg alBlockSiz eException , ShortBuf ferExcepti on, | |
336 | BadPa ddingExcep tion { | |
337 | re turn core. doFinal(in put, input Offset, in putLen, ou tput, | |
338 | ou tputOffset ); | |
339 | } | |
340 | ||
341 | /** | |
342 | * Ret urns the p arameters used with this ciphe r. | |
343 | * | |
344 | * <p> The return ed paramet ers may be the same that were used to in itialize | |
345 | * thi s cipher, or may con tain the d efault set of parame ters or a set of | |
346 | * ran domly gene rated para meters use d by the u nderlying cipher | |
347 | * imp lementatio n (provide d that the underlyin g cipher i mplementat ion | |
348 | * use s a defaul t set of p arameters or creates new param eters if i t needs | |
349 | * par ameters bu t was not initialize d with any ). | |
350 | * | |
351 | * @re turn the p arameters used with this ciphe r, or null if this c ipher | |
352 | * doe s not use any parame ters. | |
353 | */ | |
354 | protec ted Algori thmParamet ers engine GetParamet ers() { | |
355 | re turn core. getParamet ers("DESed e"); | |
356 | } | |
357 | ||
358 | /** | |
359 | * Re turns the key size o f the give n key obje ct. | |
360 | * | |
361 | * @pa ram key th e key obje ct. | |
362 | * | |
363 | * @re turn the " effective" key size of the giv en key obj ect. | |
364 | * | |
365 | * @ex ception In validKeyEx ception if <code>key </code> is invalid. | |
366 | */ | |
367 | protec ted int en gineGetKey Size(Key k ey) throws InvalidKe yException { | |
368 | by te[] encod ed = key.g etEncoded( ); | |
369 | if (encoded. length != 24) { | |
370 | throw ne w InvalidK eyExceptio n("Invalid key lengt h: " + | |
371 | enco ded.length + " bytes "); | |
372 | } | |
373 | // Return th e effectiv e key leng th | |
374 | re turn 112; | |
375 | } | |
376 | ||
377 | /** | |
378 | * Wra p a key. | |
379 | * | |
380 | * @pa ram key th e key to b e wrapped. | |
381 | * | |
382 | * @re turn the w rapped key . | |
383 | * | |
384 | * @ex ception Il legalBlock SizeExcept ion if thi s cipher i s a block | |
385 | * cip her, no pa dding has been reque sted, and the length of the | |
386 | * enc oding of t he key to be wrapped is not a | |
387 | * mul tiple of t he block s ize. | |
388 | * | |
389 | * @ex ception In validKeyEx ception if it is imp ossible or unsafe to | |
390 | * wra p the key with this cipher (e. g., a hard ware prote cted key i s | |
391 | * bei ng passed to a softw are only c ipher). | |
392 | */ | |
393 | protec ted byte[] engineWra p(Key key) | |
394 | th rows Illeg alBlockSiz eException , InvalidK eyExceptio n { | |
395 | re turn core. wrap(key); | |
396 | } | |
397 | ||
398 | /** | |
399 | * Unw rap a prev iously wra pped key. | |
400 | * | |
401 | * @pa ram wrappe dKey the k ey to be u nwrapped. | |
402 | * | |
403 | * @pa ram wrappe dKeyAlgori thm the al gorithm th e wrapped key is for . | |
404 | * | |
405 | * @pa ram wrappe dKeyType t he type of the wrapp ed key. | |
406 | * Thi s is one o f <code>Ci pher.SECRE T_KEY</cod e>, | |
407 | * <co de>Cipher. PRIVATE_KE Y</code>, or <code>C ipher.PUBL IC_KEY</co de>. | |
408 | * | |
409 | * @re turn the u nwrapped k ey. | |
410 | * | |
411 | * @ex ception No SuchAlgori thmExcepti on if no i nstalled p roviders | |
412 | * can create ke ys of type <code>wra ppedKeyTyp e</code> f or the | |
413 | * <co de>wrapped KeyAlgorit hm</code>. | |
414 | * | |
415 | * @ex ception In validKeyEx ception if <code>wra ppedKey</c ode> does not | |
416 | * rep resent a w rapped key of type < code>wrapp edKeyType< /code> for | |
417 | * the <code>wra ppedKeyAlg orithm</co de>. | |
418 | */ | |
419 | protec ted Key en gineUnwrap (byte[] wr appedKey, | |
420 | Str ing wrappe dKeyAlgori thm, | |
421 | int wrappedKe yType) | |
422 | th rows Inval idKeyExcep tion, NoSu chAlgorith mException { | |
423 | re turn core. unwrap(wra ppedKey, w rappedKeyA lgorithm, | |
424 | wra ppedKeyTyp e); | |
425 | } | |
426 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.