@@ -95,7 +95,7 @@ public static synchronized Path generateClasspathJar(String[] classPaths) throws
9595 // In jar manifest, the absolute path C:\a.jar should be converted to the url style file:///C:/a.jar
9696 String classpathValue = String .join (" " , classpathUrls );
9797 attributes .put (Attributes .Name .CLASS_PATH , classpathValue );
98- String baseName = "cp_" + getMd5 (classpathValue );
98+ String baseName = "cp_" + getSha256 (classpathValue );
9999 cleanupTempFiles (baseName , ".jar" );
100100 Path tempfile = createTempFile (baseName , ".jar" );
101101 JarOutputStream jar = new JarOutputStream (new FileOutputStream (tempfile .toFile ()), manifest );
@@ -127,7 +127,7 @@ public static synchronized Path generateArgfile(String vmArgs, String[] classPat
127127 }
128128
129129 argfile = argfile .replace ("\\ " , "\\ \\ " );
130- String baseName = "cp_" + getMd5 (argfile );
130+ String baseName = "cp_" + getSha256 (argfile );
131131 cleanupTempFiles (baseName , ".argfile" );
132132 Path tempfile = createTempFile (baseName , ".argfile" );
133133 Files .writeString (tempfile , argfile , encoding );
@@ -364,12 +364,15 @@ private static Path createTempFile(String baseName, String suffix) throws IOExce
364364 }
365365 }
366366
367- private static String getMd5 (String input ) {
367+ private static String getSha256 (String input ) {
368368 try {
369- MessageDigest md = MessageDigest .getInstance ("MD5 " );
369+ MessageDigest md = MessageDigest .getInstance ("SHA-256 " );
370370 byte [] messageDigest = md .digest (input .getBytes ());
371- BigInteger md5 = new BigInteger (1 , messageDigest );
372- return md5 .toString (Character .MAX_RADIX );
371+ // Use only first 16 bytes to keep filename shorter
372+ byte [] truncated = new byte [16 ];
373+ System .arraycopy (messageDigest , 0 , truncated , 0 , 16 );
374+ BigInteger hash = new BigInteger (1 , truncated );
375+ return hash .toString (Character .MAX_RADIX );
373376 } catch (NoSuchAlgorithmException e ) {
374377 return Integer .toString (input .hashCode (), Character .MAX_RADIX );
375378 }
0 commit comments