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