1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.crypto.password.params; |
21 |
|
|
22 |
|
import java.security.SecureRandom; |
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
@version |
28 |
|
@since |
29 |
|
|
|
|
| 66% |
Uncovered Elements: 18 (53) |
Complexity: 24 |
Complexity Density: 0.83 |
|
30 |
|
public class PBKDF2Parameters extends KeyDerivationFunctionParameters |
31 |
|
{ |
32 |
|
private static final int SALT_DEFAULT_SIZE = 16; |
33 |
|
|
34 |
|
private static final int DEFAULT_MIN_ITER = 1000; |
35 |
|
|
36 |
|
private static final int DEFAULT_ITER_RANGE = 2000; |
37 |
|
|
38 |
|
private static final SecureRandom PRND = new SecureRandom(); |
39 |
|
|
40 |
|
private final byte[] salt; |
41 |
|
|
42 |
|
private final int iterationCount; |
43 |
|
|
44 |
|
private final String prf; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
@value |
50 |
|
@value@value@value |
51 |
|
|
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
53 |
1 |
public PBKDF2Parameters()... |
54 |
|
{ |
55 |
1 |
this(-1); |
56 |
|
} |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
@value |
62 |
|
@value@value@value |
63 |
|
|
64 |
|
|
65 |
|
@param |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
1 |
public PBKDF2Parameters(SecureRandom random)... |
68 |
|
{ |
69 |
1 |
this(-1, random); |
70 |
|
} |
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
@value |
76 |
|
@value@value@value |
77 |
|
|
78 |
|
@param |
79 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
80 |
0 |
public PBKDF2Parameters(String prf)... |
81 |
|
{ |
82 |
0 |
this(-1, getRandomIterationCount(PRND), getRandomSalt(PRND), prf); |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
@param |
89 |
|
@param |
90 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
91 |
0 |
public PBKDF2Parameters(String prf, SecureRandom random)... |
92 |
|
{ |
93 |
0 |
this(-1, getRandomIterationCount(random), getRandomSalt(random), prf); |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
@value |
100 |
|
@value@value@value |
101 |
|
|
102 |
|
|
103 |
|
@param |
104 |
|
|
105 |
|
|
106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
107 |
5 |
public PBKDF2Parameters(int keySize)... |
108 |
|
{ |
109 |
5 |
this(keySize, getRandomIterationCount(PRND), getRandomSalt(PRND), null); |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
@value |
116 |
|
@value@value@value |
117 |
|
|
118 |
|
|
119 |
|
@param |
120 |
|
|
121 |
|
@param |
122 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
123 |
1 |
public PBKDF2Parameters(int keySize, SecureRandom random)... |
124 |
|
{ |
125 |
1 |
this(keySize, getRandomIterationCount(random), getRandomSalt(random), null); |
126 |
|
} |
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
@value |
132 |
|
@value@value@value |
133 |
|
|
134 |
|
@param |
135 |
|
|
136 |
|
@param |
137 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
138 |
0 |
public PBKDF2Parameters(int keySize, String prf)... |
139 |
|
{ |
140 |
0 |
this(keySize, getRandomIterationCount(PRND), getRandomSalt(PRND), null); |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
@value |
147 |
|
@value@value@value |
148 |
|
|
149 |
|
@param |
150 |
|
|
151 |
|
@param |
152 |
|
@param |
153 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
154 |
0 |
public PBKDF2Parameters(int keySize, String prf, SecureRandom random)... |
155 |
|
{ |
156 |
0 |
this(keySize, getRandomIterationCount(random), getRandomSalt(random), null); |
157 |
|
} |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
@value |
163 |
|
|
164 |
|
|
165 |
|
@param |
166 |
|
|
167 |
|
@param |
168 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
169 |
6 |
public PBKDF2Parameters(int keySize, int iterationCount)... |
170 |
|
{ |
171 |
6 |
this(keySize, iterationCount, getRandomSalt(PRND), null); |
172 |
|
} |
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
@value |
178 |
|
|
179 |
|
|
180 |
|
@param |
181 |
|
|
182 |
|
@param |
183 |
|
@param |
184 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
185 |
0 |
public PBKDF2Parameters(int keySize, int iterationCount, SecureRandom random)... |
186 |
|
{ |
187 |
0 |
this(keySize, iterationCount, getRandomSalt(random), null); |
188 |
|
} |
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
@value |
194 |
|
|
195 |
|
@param |
196 |
|
|
197 |
|
@param |
198 |
|
@param |
199 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
200 |
4 |
public PBKDF2Parameters(int keySize, int iterationCount, String prf)... |
201 |
|
{ |
202 |
4 |
this(keySize, iterationCount, getRandomSalt(PRND), prf); |
203 |
|
} |
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
@value |
209 |
|
|
210 |
|
@param |
211 |
|
|
212 |
|
@param |
213 |
|
@param |
214 |
|
@param |
215 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
216 |
0 |
public PBKDF2Parameters(int keySize, int iterationCount, String prf, SecureRandom random)... |
217 |
|
{ |
218 |
0 |
this(keySize, iterationCount, getRandomSalt(random), prf); |
219 |
|
} |
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
@value@value@value |
226 |
|
|
227 |
|
|
228 |
|
@param |
229 |
|
|
230 |
|
@param |
231 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
232 |
4 |
public PBKDF2Parameters(int keySize, byte[] salt)... |
233 |
|
{ |
234 |
4 |
this(keySize, getRandomIterationCount(PRND), salt, null); |
235 |
|
} |
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
@value@value@value |
242 |
|
|
243 |
|
|
244 |
|
@param |
245 |
|
|
246 |
|
@param |
247 |
|
@param |
248 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
249 |
0 |
public PBKDF2Parameters(int keySize, byte[] salt, SecureRandom random)... |
250 |
|
{ |
251 |
0 |
this(keySize, getRandomIterationCount(random), salt, null); |
252 |
|
} |
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
@value@value@value |
259 |
|
|
260 |
|
@param |
261 |
|
|
262 |
|
@param |
263 |
|
@param |
264 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
265 |
0 |
public PBKDF2Parameters(int keySize, byte[] salt, String prf)... |
266 |
|
{ |
267 |
0 |
this(keySize, getRandomIterationCount(PRND), salt, prf); |
268 |
|
} |
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
@value@value@value |
275 |
|
|
276 |
|
@param |
277 |
|
|
278 |
|
@param |
279 |
|
@param |
280 |
|
@param |
281 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
282 |
0 |
public PBKDF2Parameters(int keySize, byte[] salt, String prf, SecureRandom random)... |
283 |
|
{ |
284 |
0 |
this(keySize, getRandomIterationCount(random), salt, prf); |
285 |
|
} |
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
|
290 |
|
@param |
291 |
|
|
292 |
|
@param |
293 |
|
@param |
294 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
295 |
11 |
public PBKDF2Parameters(int keySize, int iterationCount, byte[] salt)... |
296 |
|
{ |
297 |
11 |
this(keySize, iterationCount, salt, null); |
298 |
|
} |
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
@param |
304 |
|
|
305 |
|
@param |
306 |
|
@param |
307 |
|
@param |
308 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
309 |
45 |
public PBKDF2Parameters(int keySize, int iterationCount, byte[] salt, String prf)... |
310 |
|
{ |
311 |
45 |
super(keySize); |
312 |
45 |
this.salt = salt; |
313 |
45 |
this.iterationCount = iterationCount; |
314 |
45 |
this.prf = prf; |
315 |
|
} |
316 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
317 |
10 |
private static int getRandomIterationCount(SecureRandom random)... |
318 |
|
{ |
319 |
10 |
return random.nextInt(DEFAULT_ITER_RANGE) + DEFAULT_MIN_ITER; |
320 |
|
} |
321 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
322 |
16 |
private static byte[] getRandomSalt(SecureRandom random)... |
323 |
|
{ |
324 |
16 |
byte[] salt = new byte[SALT_DEFAULT_SIZE]; |
325 |
16 |
random.nextBytes(salt); |
326 |
16 |
return salt; |
327 |
|
} |
328 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
329 |
13 |
@Override... |
330 |
|
public String getAlgorithmName() |
331 |
|
{ |
332 |
13 |
return "PKCS5S2"; |
333 |
|
} |
334 |
|
|
335 |
|
|
336 |
|
@return |
337 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
338 |
81 |
public int getIterationCount()... |
339 |
|
{ |
340 |
81 |
return this.iterationCount; |
341 |
|
} |
342 |
|
|
343 |
|
|
344 |
|
@return |
345 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
346 |
81 |
public byte[] getSalt()... |
347 |
|
{ |
348 |
81 |
return this.salt; |
349 |
|
} |
350 |
|
|
351 |
|
|
352 |
|
@return |
353 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
354 |
77 |
public String getPseudoRandomFuntionHint()... |
355 |
|
{ |
356 |
77 |
return this.prf; |
357 |
|
} |
358 |
|
} |