package com.example.utils;
|
|
import java.security.MessageDigest;
|
import java.security.NoSuchAlgorithmException;
|
|
public class Md5Util {
|
|
public static String encrypt(String input) {
|
if (input == null || input.isEmpty()) {
|
return null;
|
}
|
try {
|
MessageDigest md = MessageDigest.getInstance("SHA-1");
|
byte[] digest = md.digest(input.getBytes());
|
StringBuilder sb = new StringBuilder();
|
for (byte b : digest) {
|
sb.append(String.format("%02x", b));
|
}
|
return sb.toString();
|
} catch (NoSuchAlgorithmException e) {
|
throw new RuntimeException("加密失败", e);
|
}
|
}
|
}
|