MD5 32位 小写加密和大写加密

    xiaoxiao2026-03-09  8

    public class MD5Utils { /* * 加密算法 */ public static String encode(String text){ try { MessageDigest digest = MessageDigest.getInstance("md5"); byte[] result = digest.digest(text.getBytes()); StringBuilder sb =new StringBuilder(); for(byte b:result){ int number = b&0xff; String hex = Integer.toHexString(number); if(hex.length() == 1){ sb.append("0"+hex); }else{ sb.append(hex); } } return sb.toString(); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } return "" ; } }

    以上返回的是小写的加密字符串

    如果想得到大写的加密字符串只要在return sb.toString();这句话后面加上.toUpperCase()即可;

    return sb.toString().toUpperCase();

    转载请注明原文地址: https://ju.6miu.com/read-1307793.html
    最新回复(0)