编辑代码

import java.security.MessageDigest;   
import java.security.NoSuchAlgorithmException;   
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
   
import java.security.MessageDigest;

public class test {

    public static void main(String[] args) {
        /*String input = new String(
                "qrContent=ESMAUTHQRv001071BC5069359421D8CA84E190D8A68AC&serviceId=7b04dca2e2234861814a5fc1d19745fc".getBytes(StandardCharsets.UTF_8),
                StandardCharsets.UTF_8);*/
        String input = "qrContent=ESMAUTHQRv001071BC5069359421D8CA84E190D8A68AC&serviceId=7b04dca2e2234861814a5fc1d19745fc";
        System.out.println("input:" + input+"-len:"+ input.length());
        try {
            byte[] inputBytes = input.getBytes(StandardCharsets.UTF_8);
            System.out.println("输入字节长度: " + inputBytes.length);
            System.out.println("输入字节值: " + Arrays.toString(inputBytes));
            System.out.println("input: " + new String(inputBytes,StandardCharsets.UTF_8));
            MessageDigest md = java.security.MessageDigest.getInstance("MD5");
            byte[] hashBytes = md.digest(inputBytes);
            StringBuilder hexString = new StringBuilder();
            for (byte b : hashBytes) {
                String hex = String.format("%02x", b & 0xff); // 保留前导零
                hexString.append(hex);
            }
            System.out.println("MD5 摘要: " + hexString.toString());
        } catch (NoSuchAlgorithmException e) {
            System.err.println("MD5 算法不可用: " + e.getMessage());
        }
    }
}