From 72a108f960896c282bf1e4dd4dedb6bbfc3c29f5 Mon Sep 17 00:00:00 2001 From: Philippus Baalman Date: Fri, 23 Aug 2019 00:23:46 +0200 Subject: [PATCH 1/3] Drop last 4 bytes of computed SHA-1 hash --- .../src/main/java/com/baeldung/uuid/UUIDGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java b/core-java-modules/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java index dcf186de93..70217cd556 100644 --- a/core-java-modules/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java +++ b/core-java-modules/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java @@ -67,7 +67,7 @@ public class UUIDGenerator { } catch (NoSuchAlgorithmException nsae) { throw new InternalError("MD5 not supported", nsae); } - byte[] bytes = md.digest(name); + byte[] bytes = Arrays.copyOfRange(md.digest(name), 0, 16); bytes[6] &= 0x0f; /* clear version */ bytes[6] |= 0x50; /* set to version 5 */ bytes[8] &= 0x3f; /* clear variant */ From ad54ac6f5e569654f72d29d961bf6f3a16edfb1d Mon Sep 17 00:00:00 2001 From: Philippus Baalman Date: Fri, 23 Aug 2019 00:29:27 +0200 Subject: [PATCH 2/3] Fix message for exception --- .../src/main/java/com/baeldung/uuid/UUIDGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java b/core-java-modules/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java index 70217cd556..c4663a429c 100644 --- a/core-java-modules/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java +++ b/core-java-modules/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java @@ -65,7 +65,7 @@ public class UUIDGenerator { try { md = MessageDigest.getInstance("SHA-1"); } catch (NoSuchAlgorithmException nsae) { - throw new InternalError("MD5 not supported", nsae); + throw new InternalError("SHA-1 not supported", nsae); } byte[] bytes = Arrays.copyOfRange(md.digest(name), 0, 16); bytes[6] &= 0x0f; /* clear version */ From 2747b3b5e49e1e55e782481ada4ecec9aaddcc42 Mon Sep 17 00:00:00 2001 From: Eric Martin Date: Thu, 5 Sep 2019 14:45:00 -0500 Subject: [PATCH 3/3] import java.util.Arrays; --- .../core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java b/core-java-modules/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java index c4663a429c..2659b29491 100644 --- a/core-java-modules/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java +++ b/core-java-modules/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java @@ -3,6 +3,7 @@ package com.baeldung.uuid; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.Arrays; import java.util.UUID; public class UUIDGenerator {