MessageDigest??Java???????????,???????????ID?????????????,??????MessageDigest????ID:
import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class UniqueIDGenerator { public static String generateUniqueID(String input) { try { // ??MessageDigest?? MessageDigest md = MessageDigest.getInstance("MD5"); // ????????????? byte[] inputBytes = input.getBytes(); // ???? byte[] digest = md.digest(inputBytes); // ????????????? StringBuilder sb = new StringBuilder(); for (byte b : digest) { sb.append(String.format("x", b)); } return sb.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } } public static void main(String[] args) { String input = "Hello, world!"; String uniqueID = generateUniqueID(input); System.out.println("Unique ID: " + uniqueID); } }
??????,????MD5???????ID,????????????????????ID?????????????generateUniqueID
??,?????????ID????