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