aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/helper
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-12-30 03:29:45 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-12-30 02:29:45 +1300
commit5fbff0086bbfec254865cdf8833f7a4ad649c104 (patch)
tree8abbdc6494803a579086cc071e0f325ce17974ca /src/org/traccar/helper
parent246045a3865ec01efeb9318adc1d0ec2539cd908 (diff)
downloadtrackermap-server-5fbff0086bbfec254865cdf8833f7a4ad649c104.tar.gz
trackermap-server-5fbff0086bbfec254865cdf8833f7a4ad649c104.tar.bz2
trackermap-server-5fbff0086bbfec254865cdf8833f7a4ad649c104.zip
Init crypto on statup (fix #2422)
Diffstat (limited to 'src/org/traccar/helper')
-rw-r--r--src/org/traccar/helper/Hashing.java15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/org/traccar/helper/Hashing.java b/src/org/traccar/helper/Hashing.java
index 55086bac7..47d263fca 100644
--- a/src/org/traccar/helper/Hashing.java
+++ b/src/org/traccar/helper/Hashing.java
@@ -19,7 +19,9 @@ import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.xml.bind.DatatypeConverter;
import java.security.GeneralSecurityException;
+import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
+import java.security.spec.InvalidKeySpecException;
public final class Hashing {
@@ -27,6 +29,14 @@ public final class Hashing {
public static final int SALT_SIZE = 24;
public static final int HASH_SIZE = 24;
+ private static SecretKeyFactory factory;
+ static {
+ try {
+ factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
+ } catch (NoSuchAlgorithmException e) {
+ }
+ }
+
public static class HashingResult {
private final String hash;
@@ -52,10 +62,9 @@ public final class Hashing {
private static byte[] function(char[] password, byte[] salt) {
try {
PBEKeySpec spec = new PBEKeySpec(password, salt, ITERATIONS, HASH_SIZE * Byte.SIZE);
- SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
return factory.generateSecret(spec).getEncoded();
- } catch (GeneralSecurityException error) {
- throw new SecurityException(error);
+ } catch (InvalidKeySpecException e) {
+ throw new SecurityException(e);
}
}