|
30 | 30 | import org.apache.shiro.crypto.hash.DefaultHashService; |
31 | 31 | import org.apache.shiro.crypto.hash.Hash; |
32 | 32 | import org.apache.shiro.crypto.hash.HashRequest; |
| 33 | +import org.apache.shiro.crypto.hash.SimpleHashProvider; |
33 | 34 | import org.apache.shiro.crypto.hash.SimpleHashRequest; |
34 | 35 | import org.apache.shiro.crypto.hash.format.DefaultHashFormatFactory; |
35 | 36 | import org.apache.shiro.crypto.hash.format.HashFormat; |
|
49 | 50 | import java.io.File; |
50 | 51 | import java.io.IOException; |
51 | 52 | import java.io.InputStreamReader; |
52 | | -import java.util.Arrays; |
53 | 53 |
|
54 | | -import static java.util.Collections.emptyMap; |
| 54 | +import java.util.Arrays; |
| 55 | +import java.util.Map; |
| 56 | +import java.util.concurrent.ConcurrentHashMap; |
55 | 57 |
|
56 | 58 | /** |
57 | 59 | * Commandline line utility to hash data such as strings, passwords, resources (files, urls, etc.). |
@@ -244,18 +246,22 @@ public static void main(String[] args) { |
244 | 246 | } |
245 | 247 | } |
246 | 248 |
|
| 249 | + Map<String, Object> parameters = new ConcurrentHashMap<>(); |
| 250 | + |
247 | 251 | if (iterations < DEFAULT_NUM_ITERATIONS) { |
248 | 252 | //Iterations were not specified. Default to 350,000 when password hashing, and 1 for everything else: |
249 | 253 | if (password) { |
250 | 254 | iterations = DEFAULT_PASSWORD_NUM_ITERATIONS; |
251 | 255 | } else { |
252 | 256 | iterations = DEFAULT_NUM_ITERATIONS; |
253 | 257 | } |
| 258 | + } else { |
| 259 | + //Iterations were specified, so add the iterations parameter: |
| 260 | + parameters.put(SimpleHashProvider.Parameters.PARAMETER_ITERATIONS, iterations); |
254 | 261 | } |
255 | 262 |
|
256 | 263 | ByteSource publicSalt = getSalt(saltString, saltBytesString, generateSalt, generatedSaltSize); |
257 | | - // FIXME: add options here. |
258 | | - HashRequest hashRequest = new SimpleHashRequest(algorithm, ByteSource.Util.bytes(source), publicSalt, emptyMap()); |
| 264 | + HashRequest hashRequest = new SimpleHashRequest(algorithm, ByteSource.Util.bytes(source), publicSalt, parameters); |
259 | 265 |
|
260 | 266 | DefaultHashService hashService = new DefaultHashService(); |
261 | 267 | Hash hash = hashService.computeHash(hashRequest); |
|
0 commit comments