diff options
Diffstat (limited to 'src/org/traccar/helper')
-rw-r--r-- | src/org/traccar/helper/Hashing.java | 15 |
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); } } |