Produced by Araxis Merge on 9/25/2018 2:13:02 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 | HmacPKCS12PBESHA1.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 | HmacPKCS12PBESHA1.java | Wed Sep 12 16:22:31 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 3 | 266 |
Changed | 2 | 4 |
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 co m.sun.cryp to.provide r; | |
27 | ||
28 | import jav a.util.Arr ays; | |
29 | import jav a.nio.Byte Buffer; | |
30 | ||
31 | import jav ax.crypto. MacSpi; | |
32 | import jav ax.crypto. SecretKey; | |
33 | import jav ax.crypto. spec.Secre tKeySpec; | |
34 | import jav ax.crypto. spec.PBEPa rameterSpe c; | |
35 | import jav a.security .*; | |
36 | import jav a.security .spec.*; | |
37 | ||
38 | /** | |
39 | * This is an implem entation o f the HMAC -PBESHA1 a lgorithm a s defined | |
40 | * in PKCS #12 v1.0 s tandard. | |
41 | * | |
42 | * @author Valerie P eng | |
43 | */ | |
44 | public fin al class H macPKCS12P BESHA1 ext ends HmacC ore { | |
45 | ||
46 | /** | |
47 | * Sta ndard cons tructor, c reates a n ew HmacSHA 1 instance . | |
48 | */ | |
49 | public HmacPKCS1 2PBESHA1() throws No SuchAlgori thmExcepti on { | |
50 | su per("SHA1" , 64); | |
51 | } | |
52 | ||
53 | /** | |
54 | * Initiali zes the HM AC with th e given PW key and al gorithm pa rameters. | |
55 | * | |
56 | * @param k ey the PW key. | |
57 | * @pa ram params the algor ithm param eters. | |
58 | * | |
59 | * @ex ception In validKeyEx ception if the given key is in appropriat e for | |
60 | * ini tializing this MAC. | |
61 | * @ex ception In validAlgor ithmParame terExcepti on if the given algo rithm | |
62 | * par ameters ar e inapprop riate for this MAC. | |
63 | */ | |
64 | protec ted void e ngineInit( Key key, A lgorithmPa rameterSpe c params) | |
65 | th rows Inval idKeyExcep tion, Inva lidAlgorit hmParamete rException { | |
66 | ch ar[] passw dChars; | |
67 | by te[] salt = null; | |
68 | in t iCount = 0; | |
69 | if (key inst anceof jav ax.crypto. interfaces .PBEKey) { | |
70 | javax.cr ypto.inter faces.PBEK ey pbeKey = | |
71 | (jav ax.crypto. interfaces .PBEKey) k ey; | |
72 | passwdCh ars = pbeK ey.getPass word(); | |
73 | salt = p beKey.getS alt(); // maybe null if unspec ified | |
74 | iCount = pbeKey.ge tIteration Count(); / / maybe 0 if unspeci fied | |
75 | } else if (k ey instanc eof Secret Key) { | |
76 | byte[] p asswdBytes = key.get Encoded(); | |
77 | if ((pas swdBytes = = null) || | |
78 | !(ke y.getAlgor ithm().reg ionMatches (true, 0, "PBE", 0, 3))) { | |
79 | thro w new Inva lidKeyExce ption("Mis sing passw ord"); | |
80 | } | |
81 | passwdCh ars = new char[passw dBytes.len gth]; | |
82 | for (int i=0; i<pa sswdChars. length; i+ +) { | |
83 | pass wdChars[i] = (char) (passwdByt es[i] & 0x 7f); | |
84 | } | |
85 | } else { | |
86 | throw ne w InvalidK eyExceptio n("SecretK ey of PBE type requi red"); | |
87 | } | |
88 | if (params = = null) { | |
89 | // shoul d not auto -generate default va lues since current | |
90 | // javax .crypto.Ma c api does not have any method for calle r to | |
91 | // retri eve the ge nerated de faults. | |
92 | if ((sal t == null) || (iCoun t == 0)) { | |
93 | thro w new Inva lidAlgorit hmParamete rException | |
94 | ("PBEParam eterSpec r equired fo r salt and iteration count"); | |
95 | } | |
96 | } else if (! (params in stanceof P BEParamete rSpec)) { | |
97 | throw ne w InvalidA lgorithmPa rameterExc eption | |
98 | ("PB EParameter Spec type required") ; | |
99 | } else { | |
100 | PBEParam eterSpec p beParams = (PBEParam eterSpec) params; | |
101 | // make sure the p arameter v alues are consistent | |
102 | if (salt != null) { | |
103 | if ( !Arrays.eq uals(salt, pbeParams .getSalt() )) { | |
104 | throw new InvalidAlg orithmPara meterExcep tion | |
105 | ("Inco nsistent v alue of sa lt between key and p arams"); | |
106 | } | |
107 | } else { | |
108 | salt = pbePara ms.getSalt (); | |
109 | } | |
110 | if (iCou nt != 0) { | |
111 | if ( iCount != pbeParams. getIterati onCount()) { | |
112 | throw new InvalidAlg orithmPara meterExcep tion | |
113 | ("Diff erent iter ation coun t between key and pa rams"); | |
114 | } | |
115 | } else { | |
116 | iCou nt = pbePa rams.getIt erationCou nt(); | |
117 | } | |
118 | } | |
119 | // For secur ity purpos e, we need to enforc e a minimu m length | |
120 | // for salt; just requ ire the mi nimum salt length to be 8-byte | |
121 | // which is what PKCS# 5 recommen ds and ope nssl does. | |
122 | if (salt.len gth < 8) { | |
123 | throw ne w InvalidA lgorithmPa rameterExc eption | |
124 | ("Sa lt must be at least 8 bytes lo ng"); | |
125 | } | |
126 | if (iCount < = 0) { | |
127 | throw ne w InvalidA lgorithmPa rameterExc eption | |
128 | ("It erationCou nt must be a positiv e number") ; | |
129 | } | |
130 | by te[] deriv edKey = PK CS12PBECip herCore.de rive(passw dChars, sa lt, | |
131 | iCount, engineGetM acLength() , PKCS12PB ECipherCor e.MAC_KEY) ; | |
132 | Se cretKey ci pherKey = new Secret KeySpec(de rivedKey, "HmacSHA1" ); | |
133 | su per.engine Init(ciphe rKey, null ); | |
134 | } | |
135 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.