diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/helper/ChannelBufferTools.java | 19 | ||||
-rw-r--r-- | src/org/traccar/helper/Hashing.java | 9 |
2 files changed, 6 insertions, 22 deletions
diff --git a/src/org/traccar/helper/ChannelBufferTools.java b/src/org/traccar/helper/ChannelBufferTools.java index 99da43b54..6c61287c9 100644 --- a/src/org/traccar/helper/ChannelBufferTools.java +++ b/src/org/traccar/helper/ChannelBufferTools.java @@ -17,6 +17,7 @@ package org.traccar.helper; import org.jboss.netty.buffer.ChannelBuffer; +import javax.xml.bind.DatatypeConverter; import java.util.Formatter; public final class ChannelBufferTools { @@ -89,22 +90,4 @@ public final class ChannelBufferTools { return value; } - public static byte[] hexToBytes(String in) { - int count = in.length() / 2; - byte[] out = new byte[count]; - for (int i = 0; i < count; i++) { - out[i] = (byte) Integer.parseInt(in.substring(i * 2, (i + 1) * 2), 16); - } - return out; - } - - public static String bytesToHex(byte[] in) { - StringBuilder out = new StringBuilder(); - Formatter formatter = new Formatter(out); - for (byte b : in) { - formatter.format("%02x", b); - } - return out.toString(); - } - } diff --git a/src/org/traccar/helper/Hashing.java b/src/org/traccar/helper/Hashing.java index cdc5c7ae5..29020f3a7 100644 --- a/src/org/traccar/helper/Hashing.java +++ b/src/org/traccar/helper/Hashing.java @@ -19,6 +19,7 @@ import java.security.GeneralSecurityException; import java.security.SecureRandom; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.PBEKeySpec; +import javax.xml.bind.DatatypeConverter; public final class Hashing { @@ -65,13 +66,13 @@ public final class Hashing { RANDOM.nextBytes(salt); byte[] hash = function(password.toCharArray(), salt); return new HashingResult( - ChannelBufferTools.bytesToHex(hash), - ChannelBufferTools.bytesToHex(salt)); + DatatypeConverter.printHexBinary(hash), + DatatypeConverter.printHexBinary(salt)); } public static boolean validatePassword(String password, String hashHex, String saltHex) { - byte[] hash = ChannelBufferTools.hexToBytes(hashHex); - byte[] salt = ChannelBufferTools.hexToBytes(saltHex); + byte[] hash = DatatypeConverter.parseHexBinary(hashHex); + byte[] salt = DatatypeConverter.parseHexBinary(saltHex); return slowEquals(hash, function(password.toCharArray(), salt)); } |