diff options
Diffstat (limited to 'eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/Random.java')
-rw-r--r-- | eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/Random.java | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/Random.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/Random.java index aedbbb7f..6c0a288f 100644 --- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/Random.java +++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/Random.java @@ -19,16 +19,16 @@ package at.gv.egiz.eaaf.core.impl.utils; -import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; -import org.apache.commons.codec.binary.Hex; import org.apache.commons.lang3.ArrayUtils; +import org.apache.hc.client5.http.utils.Hex; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -83,19 +83,14 @@ public class Random { // generate ID String returnValue; - try { - returnValue = preFix + new String(Hex.encodeHex(ArrayUtils.addAll(now.getBytes("UTF-8"), randValue))); - - // 20 bytes = 160 bits - if (returnValue.length() > 40) { - return returnValue.substring(0, 40); - } else { - return returnValue; - } - - } catch (final UnsupportedEncodingException e) { - throw new RuntimeException(e); - + returnValue = preFix + new String(Hex.encodeHexString( + ArrayUtils.addAll(now.getBytes(StandardCharsets.UTF_8), randValue))); + + // 20 bytes = 160 bits + if (returnValue.length() > 40) { + return returnValue.substring(0, 40); + } else { + return returnValue; } } @@ -106,7 +101,7 @@ public class Random { * @return random hex encoded value [256bit] */ public static String nextHexRandom32() { - return new String(Hex.encodeHex(nextByteRandom(32))); // 32 bytes = 256 bits + return new String(Hex.encodeHexString(nextByteRandom(32))); // 32 bytes = 256 bits } @@ -116,7 +111,7 @@ public class Random { * @return random hex encoded value [128bit] */ public static String nextHexRandom16() { - return new String(Hex.encodeHex(nextByteRandom(16))); // 16 bytes = 128 bits + return new String(Hex.encodeHexString(nextByteRandom(16))); // 16 bytes = 128 bits } |