Skip to content

Commit 3927b9e

Browse files
authored
Merge pull request apache#2324 from ntolppi/feature-iterations-parameter
Added support for iterations parameter
2 parents 3d7b10c + 4b348b1 commit 3927b9e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

crypto/hash/src/main/java/org/apache/shiro/crypto/hash/SimpleHashProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ protected ByteSource combine(ByteSource privateSalt, ByteSource publicSalt) {
200200
}
201201
}
202202

203-
static final class Parameters {
203+
public static final class Parameters {
204204
public static final String PARAMETER_ITERATIONS = "SimpleHash.iterations";
205205

206206
/**

tools/hasher/src/main/java/org/apache/shiro/tools/hasher/Hasher.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.shiro.crypto.hash.DefaultHashService;
3131
import org.apache.shiro.crypto.hash.Hash;
3232
import org.apache.shiro.crypto.hash.HashRequest;
33+
import org.apache.shiro.crypto.hash.SimpleHashProvider;
3334
import org.apache.shiro.crypto.hash.SimpleHashRequest;
3435
import org.apache.shiro.crypto.hash.format.DefaultHashFormatFactory;
3536
import org.apache.shiro.crypto.hash.format.HashFormat;
@@ -49,9 +50,10 @@
4950
import java.io.File;
5051
import java.io.IOException;
5152
import java.io.InputStreamReader;
52-
import java.util.Arrays;
5353

54-
import static java.util.Collections.emptyMap;
54+
import java.util.Arrays;
55+
import java.util.Map;
56+
import java.util.concurrent.ConcurrentHashMap;
5557

5658
/**
5759
* Commandline line utility to hash data such as strings, passwords, resources (files, urls, etc.).
@@ -244,18 +246,22 @@ public static void main(String[] args) {
244246
}
245247
}
246248

249+
Map<String, Object> parameters = new ConcurrentHashMap<>();
250+
247251
if (iterations < DEFAULT_NUM_ITERATIONS) {
248252
//Iterations were not specified. Default to 350,000 when password hashing, and 1 for everything else:
249253
if (password) {
250254
iterations = DEFAULT_PASSWORD_NUM_ITERATIONS;
251255
} else {
252256
iterations = DEFAULT_NUM_ITERATIONS;
253257
}
258+
} else {
259+
//Iterations were specified, so add the iterations parameter:
260+
parameters.put(SimpleHashProvider.Parameters.PARAMETER_ITERATIONS, iterations);
254261
}
255262

256263
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);
259265

260266
DefaultHashService hashService = new DefaultHashService();
261267
Hash hash = hashService.computeHash(hashRequest);

0 commit comments

Comments
 (0)