Produced by Araxis Merge on 9/25/2018 2:13:10 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\spec | SecretKeySpec.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\spec | SecretKeySpec.java | Wed Sep 12 17:18:48 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 17 | 436 |
Changed | 16 | 32 |
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, 2015, 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 .spec; | |
27 | ||
28 | import jav a.security .MessageDi gest; | |
29 | import jav a.security .spec.KeyS pec; | |
30 | import jav a.util.Loc ale; | |
31 | import jav ax.crypto. SecretKey; | |
32 | ||
33 | /** | |
34 | * This cl ass specif ies a PW key in a p rovider-in dependent fashion. | |
35 | * | |
36 | * <p>It c an be used to constr uct a <cod e>SecretKe y</code> f rom a byte array, | |
37 | * without having to go throug h a (provi der-based) | |
38 | * <code>S ecretKeyFa ctory</cod e>. | |
39 | * | |
40 | * <p>This class is only usefu l for raw PW keys that can be rep resented a s | |
41 | * a byte array and have no ke y paramete rs associa ted with t hem, e.g., DES or | |
42 | * Triple DES keys. | |
43 | * | |
44 | * @author Jan Luehe | |
45 | * | |
46 | * @see ja vax.crypto .SecretKey | |
47 | * @see ja vax.crypto .SecretKey Factory | |
48 | * @since 1.4 | |
49 | */ | |
50 | public cla ss SecretK eySpec imp lements Ke ySpec, Sec retKey { | |
51 | ||
52 | privat e static f inal long serialVers ionUID = 6 5772383173 07289933L; | |
53 | ||
54 | /** | |
55 | * The PW key. | |
56 | * | |
57 | * @se rial | |
58 | */ | |
59 | privat e byte[] k ey; | |
60 | ||
61 | /** | |
62 | * The name of t he algorit hm associa ted with t his key. | |
63 | * | |
64 | * @se rial | |
65 | */ | |
66 | privat e String a lgorithm; | |
67 | ||
68 | /** | |
69 | * Construc ts a PW key from t he given b yte array. | |
70 | * | |
71 | * <p> This const ructor doe s not chec k if the g iven bytes indeed sp ecify a | |
72 | * PW key of the specified algorithm . For exam ple, if th e algorith m is | |
73 | * DES , this con structor d oes not ch eck if <co de>key</co de> is 8 b ytes | |
74 | * lon g, and als o does not check for weak or s emi-weak k eys. | |
75 | * In order for those chec ks to be p erformed, an algorit hm-specifi c | |
76 | * <i> key specif ication</i > class (i n this cas e: | |
77 | * {@l ink DESKey Spec DESKe ySpec}) | |
78 | * sho uld be use d. | |
79 | * | |
80 | * @param k ey the key material of the PW key. The c ontents of | |
81 | * the array are copied to protect a gainst sub sequent mo dification . | |
82 | * @param a lgorithm t he name of the PW -key algor ithm to be associate d | |
83 | * wit h the give n key mate rial. | |
84 | * See Appendix A in the < a href= | |
85 | * " {@docRoot} /../techno tes/guides /security/ crypto/Cry ptoSpec.ht ml#AppA"> | |
86 | * Jav a Cryptogr aphy Archi tecture Re ference Gu ide</a> | |
87 | * for informati on about s tandard al gorithm na mes. | |
88 | * @ex ception Il legalArgum entExcepti on if <cod e>algorith m</code> | |
89 | * is null or <c ode>key</c ode> is nu ll or empt y. | |
90 | */ | |
91 | public SecretKey Spec(byte[ ] key, Str ing algori thm) { | |
92 | if (key == n ull || alg orithm == null) { | |
93 | throw ne w IllegalA rgumentExc eption("Mi ssing argu ment"); | |
94 | } | |
95 | if (key.leng th == 0) { | |
96 | throw ne w IllegalA rgumentExc eption("Em pty key"); | |
97 | } | |
98 | th is.key = k ey.clone() ; | |
99 | th is.algorit hm = algor ithm; | |
100 | } | |
101 | ||
102 | /** | |
103 | * Construc ts a PW key from t he given b yte array, using the first | |
104 | * <co de>len</co de> bytes of <code>k ey</code>, starting at | |
105 | * <co de>offset< /code> inc lusive. | |
106 | * | |
107 | * <p> The bytes that constitut e the PW key are | |
108 | * tho se between <code>key [offset]</ code> and | |
109 | * <co de>key[off set+len-1] </code> in clusive. | |
110 | * | |
111 | * <p> This const ructor doe s not chec k if the g iven bytes indeed sp ecify a | |
112 | * PW key of the specified algorithm . For exam ple, if th e algorith m is | |
113 | * DES , this con structor d oes not ch eck if <co de>key</co de> is 8 b ytes | |
114 | * lon g, and als o does not check for weak or s emi-weak k eys. | |
115 | * In order for those chec ks to be p erformed, an algorit hm-specifi c key | |
116 | * spe cification class (in this case : | |
117 | * {@l ink DESKey Spec DESKe ySpec}) | |
118 | * mus t be used. | |
119 | * | |
120 | * @param k ey the key material of the PW key. The f irst | |
121 | * <co de>len</co de> bytes of the arr ay beginni ng at | |
122 | * <co de>offset< /code> inc lusive are copied to protect | |
123 | * aga inst subse quent modi fication. | |
124 | * @pa ram offset the offse t in <code >key</code > where th e key mate rial | |
125 | * sta rts. | |
126 | * @pa ram len th e length o f the key material. | |
127 | * @param a lgorithm t he name of the PW -key algor ithm to be associate d | |
128 | * wit h the give n key mate rial. | |
129 | * See Appendix A in the < a href= | |
130 | * " {@docRoot} /../techno tes/guides /security/ crypto/Cry ptoSpec.ht ml#AppA"> | |
131 | * Jav a Cryptogr aphy Archi tecture Re ference Gu ide</a> | |
132 | * for informati on about s tandard al gorithm na mes. | |
133 | * @ex ception Il legalArgum entExcepti on if <cod e>algorith m</code> | |
134 | * is null or <c ode>key</c ode> is nu ll, empty, or too sh ort, | |
135 | * i.e . {@code k ey.length- offset<len }. | |
136 | * @ex ception Ar rayIndexOu tOfBoundsE xception i s thrown i f | |
137 | * <co de>offset< /code> or <code>len< /code> ind ex bytes o utside the | |
138 | * <co de>key</co de>. | |
139 | */ | |
140 | public SecretKey Spec(byte[ ] key, int offset, i nt len, St ring algor ithm) { | |
141 | if (key == n ull || alg orithm == null) { | |
142 | throw ne w IllegalA rgumentExc eption("Mi ssing argu ment"); | |
143 | } | |
144 | if (key.leng th == 0) { | |
145 | throw ne w IllegalA rgumentExc eption("Em pty key"); | |
146 | } | |
147 | if (key.leng th-offset < len) { | |
148 | throw ne w IllegalA rgumentExc eption | |
149 | ("In valid offs et/length combinatio n"); | |
150 | } | |
151 | if (len < 0) { | |
152 | throw ne w ArrayInd exOutOfBou ndsExcepti on("len is negative" ); | |
153 | } | |
154 | th is.key = n ew byte[le n]; | |
155 | Sy stem.array copy(key, offset, th is.key, 0, len); | |
156 | th is.algorit hm = algor ithm; | |
157 | } | |
158 | ||
159 | /** | |
160 | * Returns the name o f the algo rithm asso ciated wit h this PW key. | |
161 | * | |
162 | * @return the PW key algori thm. | |
163 | */ | |
164 | public String ge tAlgorithm () { | |
165 | re turn this. algorithm; | |
166 | } | |
167 | ||
168 | /** | |
169 | * Returns the name o f the enco ding forma t for this PW key. | |
170 | * | |
171 | * @re turn the s tring "RAW ". | |
172 | */ | |
173 | public String ge tFormat() { | |
174 | re turn "RAW" ; | |
175 | } | |
176 | ||
177 | /** | |
178 | * Returns the key ma terial of this PW key. | |
179 | * | |
180 | * @re turn the k ey materia l. Returns a new arr ay | |
181 | * eac h time thi s method i s called. | |
182 | */ | |
183 | public byte[] ge tEncoded() { | |
184 | re turn this. key.clone( ); | |
185 | } | |
186 | ||
187 | /** | |
188 | * Cal culates a hash code value for the object . | |
189 | * Obj ects that are equal will also have the s ame hashco de. | |
190 | */ | |
191 | public int hashC ode() { | |
192 | in t retval = 0; | |
193 | fo r (int i = 1; i < th is.key.len gth; i++) { | |
194 | retval + = this.key [i] * i; | |
195 | } | |
196 | if (this.alg orithm.equ alsIgnoreC ase("Tripl eDES")) | |
197 | return ( retval ^= "desede".h ashCode()) ; | |
198 | el se | |
199 | return ( retval ^= | |
200 | this.algor ithm.toLow erCase(Loc ale.ENGLIS H).hashCod e()); | |
201 | } | |
202 | ||
203 | /** | |
204 | * Tes ts for equ ality betw een the sp ecified ob ject and t his | |
205 | * obj ect. Two S ecretKeySp ec objects are consi dered equa l if | |
206 | * the y are both SecretKey instances which hav e the | |
207 | * sam e case-ins ensitive a lgorithm n ame and ke y encoding . | |
208 | * | |
209 | * @pa ram obj th e object t o test for equality with this object. | |
210 | * | |
211 | * @re turn true if the obj ects are c onsidered equal, fal se if | |
212 | * <co de>obj</co de> is nul l or other wise. | |
213 | */ | |
214 | public boolean e quals(Obje ct obj) { | |
215 | if (this == obj) | |
216 | return t rue; | |
217 | ||
218 | if (!(obj in stanceof S ecretKey)) | |
219 | return f alse; | |
220 | ||
221 | St ring thatA lg = ((Sec retKey)obj ).getAlgor ithm(); | |
222 | if (!(thatAl g.equalsIg noreCase(t his.algori thm))) { | |
223 | if ((!(t hatAlg.equ alsIgnoreC ase("DESed e")) | |
224 | || !(this.alg orithm.equ alsIgnoreC ase("Tripl eDES"))) | |
225 | && ( !(thatAlg. equalsIgno reCase("Tr ipleDES")) | |
226 | || !(this. algorithm. equalsIgno reCase("DE Sede")))) | |
227 | return f alse; | |
228 | } | |
229 | ||
230 | by te[] thatK ey = ((Sec retKey)obj ).getEncod ed(); | |
231 | ||
232 | re turn Messa geDigest.i sEqual(thi s.key, tha tKey); | |
233 | } | |
234 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.