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\java\security | KeyRep.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\java\security | KeyRep.java | Wed Sep 12 17:12:16 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 390 |
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) 200 3, 2013, 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 va.securit y; | |
27 | ||
28 | import jav a.io.*; | |
29 | import jav a.util.Loc ale; | |
30 | ||
31 | import jav a.security .spec.PKCS 8EncodedKe ySpec; | |
32 | import jav a.security .spec.X509 EncodedKey Spec; | |
33 | import jav a.security .spec.Inva lidKeySpec Exception; | |
34 | ||
35 | import jav ax.crypto. SecretKeyF actory; | |
36 | import jav ax.crypto. spec.Secre tKeySpec; | |
37 | ||
38 | /** | |
39 | * Standar dized repr esentation for seria lized Key objects. | |
40 | * | |
41 | * <p> | |
42 | * | |
43 | * Note th at a seria lized Key may contai n sensitiv e informat ion | |
44 | * which s hould not be exposed in untrus ted enviro nments. S ee the | |
45 | * <a href ="../../.. /platform/ serializat ion/spec/s ecurity.ht ml"> | |
46 | * Securit y Appendix </a> | |
47 | * of the Serializat ion Specif ication fo r more inf ormation. | |
48 | * | |
49 | * @see Ke y | |
50 | * @see Ke yFactory | |
51 | * @see ja vax.crypto .spec.Secr etKeySpec | |
52 | * @see ja va.securit y.spec.X50 9EncodedKe ySpec | |
53 | * @see ja va.securit y.spec.PKC S8EncodedK eySpec | |
54 | * | |
55 | * @since 1.5 | |
56 | */ | |
57 | ||
58 | public cla ss KeyRep implements Serializa ble { | |
59 | ||
60 | privat e static f inal long serialVers ionUID = - 4757683898 830641853L ; | |
61 | ||
62 | /** | |
63 | * Key type. | |
64 | * | |
65 | * @si nce 1.5 | |
66 | */ | |
67 | public static en um Type { | |
68 | ||
69 | /** Type f or PW keys. */ | |
70 | SE CRET, | |
71 | ||
72 | /* * Type for public ke ys. */ | |
73 | PU BLIC, | |
74 | ||
75 | /* * Type for private k eys. */ | |
76 | PR IVATE, | |
77 | ||
78 | } | |
79 | ||
80 | privat e static f inal Strin g PKCS8 = "PKCS#8"; | |
81 | privat e static f inal Strin g X509 = " X.509"; | |
82 | privat e static f inal Strin g RAW = "R AW"; | |
83 | ||
84 | /** | |
85 | * Eit her one of Type.SECR ET, Type.P UBLIC, or Type.PRIVA TE | |
86 | * | |
87 | * @se rial | |
88 | */ | |
89 | privat e Type typ e; | |
90 | ||
91 | /** | |
92 | * The Key algor ithm | |
93 | * | |
94 | * @se rial | |
95 | */ | |
96 | privat e String a lgorithm; | |
97 | ||
98 | /** | |
99 | * The Key encod ing format | |
100 | * | |
101 | * @se rial | |
102 | */ | |
103 | privat e String f ormat; | |
104 | ||
105 | /** | |
106 | * The encoded K ey bytes | |
107 | * | |
108 | * @se rial | |
109 | */ | |
110 | privat e byte[] e ncoded; | |
111 | ||
112 | /** | |
113 | * Con struct the alternate Key class . | |
114 | * | |
115 | * <p> | |
116 | * | |
117 | * @pa ram type e ither one of Type.SE CRET, Type .PUBLIC, o r Type.PRI VATE | |
118 | * @pa ram algori thm the al gorithm re turned fro m | |
119 | * {@co de Key.get Algorithm( )} | |
120 | * @pa ram format the encod ing format returned from | |
121 | * {@co de Key.get Format()} | |
122 | * @pa ram encode d the enco ded bytes returned f rom | |
123 | * {@co de Key.get Encoded()} | |
124 | * | |
125 | * @ex ception Nu llPointerE xception | |
126 | * if t ype is {@c ode null}, | |
127 | * if a lgorithm i s {@code n ull}, | |
128 | * if f ormat is { @code null }, | |
129 | * or i f encoded is {@code null} | |
130 | */ | |
131 | public KeyRep(Ty pe type, S tring algo rithm, | |
132 | Stri ng format, byte[] en coded) { | |
133 | ||
134 | if (type == null || al gorithm == null || | |
135 | format = = null || encoded == null) { | |
136 | throw ne w NullPoin terExcepti on("invali d null inp ut(s)"); | |
137 | } | |
138 | ||
139 | th is.type = type; | |
140 | th is.algorit hm = algor ithm; | |
141 | th is.format = format.t oUpperCase (Locale.EN GLISH); | |
142 | th is.encoded = encoded .clone(); | |
143 | } | |
144 | ||
145 | /** | |
146 | * Res olve the K ey object. | |
147 | * | |
148 | * <p> This meth od support s three Ty pe/format combinatio ns: | |
149 | * <ul > | |
150 | * <li > Type.SEC RET/"RAW" - returns a SecretKe ySpec obje ct | |
151 | * con structed u sing encod ed key byt es and alg orithm | |
152 | * <li > Type.PUB LIC/"X.509 " - gets a KeyFactor y instance for | |
153 | * the key algor ithm, cons tructs an X509Encode dKeySpec w ith the | |
154 | * enc oded key b ytes, and generates a public k ey from th e spec | |
155 | * <li > Type.PRI VATE/"PKCS #8" - gets a KeyFact ory instan ce for | |
156 | * the key algor ithm, cons tructs a P KCS8Encode dKeySpec w ith the | |
157 | * enc oded key b ytes, and generates a private key from t he spec | |
158 | * </u l> | |
159 | * | |
160 | * <p> | |
161 | * | |
162 | * @re turn the r esolved Ke y object | |
163 | * | |
164 | * @ex ception Ob jectStream Exception if the Typ e/format | |
165 | * co mbination is unrecog nized, if the algori thm, key f ormat, or | |
166 | * en coded key bytes are unrecogniz ed/invalid , of if th e | |
167 | * re solution o f the key fails for any reason | |
168 | */ | |
169 | protec ted Object readResol ve() throw s ObjectSt reamExcept ion { | |
170 | tr y { | |
171 | if (type == Type.S ECRET && R AW.equals( format)) { | |
172 | retu rn new Sec retKeySpec (encoded, algorithm) ; | |
173 | } else i f (type == Type.PUBL IC && X509 .equals(fo rmat)) { | |
174 | KeyF actory f = KeyFactor y.getInsta nce(algori thm); | |
175 | retu rn f.gener atePublic( new X509En codedKeySp ec(encoded )); | |
176 | } else i f (type == Type.PRIV ATE && PKC S8.equals( format)) { | |
177 | KeyF actory f = KeyFactor y.getInsta nce(algori thm); | |
178 | retu rn f.gener atePrivate (new PKCS8 EncodedKey Spec(encod ed)); | |
179 | } else { | |
180 | thro w new NotS erializabl eException | |
181 | ("unre cognized t ype/format combinati on: " + | |
182 | type + "/" + for mat); | |
183 | } | |
184 | } catch (Not Serializab leExceptio n nse) { | |
185 | throw ns e; | |
186 | } catch (Exc eption e) { | |
187 | NotSeria lizableExc eption nse = new Not Serializab leExceptio n | |
188 | ("java.sec urity.Key: " + | |
189 | "[" + type + "] " + | |
190 | "[" + algo rithm + "] " + | |
191 | "[" + form at + "]"); | |
192 | nse.init Cause(e); | |
193 | throw ns e; | |
194 | } | |
195 | } | |
196 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.