Skip to content

Commit cf2d93b

Browse files
authored
Merge pull request eugenp#7628 from Philippus/patch-1
Drop last 4 bytes of computed SHA-1 hash
2 parents f87160d + 2747b3b commit cf2d93b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

core-java-modules/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.UnsupportedEncodingException;
44
import java.security.MessageDigest;
55
import java.security.NoSuchAlgorithmException;
6+
import java.util.Arrays;
67
import java.util.UUID;
78

89
public class UUIDGenerator {
@@ -65,9 +66,9 @@ public static UUID type5UUIDFromBytes(byte[] name) {
6566
try {
6667
md = MessageDigest.getInstance("SHA-1");
6768
} catch (NoSuchAlgorithmException nsae) {
68-
throw new InternalError("MD5 not supported", nsae);
69+
throw new InternalError("SHA-1 not supported", nsae);
6970
}
70-
byte[] bytes = md.digest(name);
71+
byte[] bytes = Arrays.copyOfRange(md.digest(name), 0, 16);
7172
bytes[6] &= 0x0f; /* clear version */
7273
bytes[6] |= 0x50; /* set to version 5 */
7374
bytes[8] &= 0x3f; /* clear variant */

0 commit comments

Comments
 (0)