Get MD5 String from Message Digest

前端 未结 11 1187
伪装坚强ぢ
伪装坚强ぢ 2020-12-23 20:46

I understand how it works but if I want to print out the MD5 as String how would I do that?

public static void getMD5(String fileName) throws Exception{
            


        
11条回答
  •  伪装坚强ぢ
    2020-12-23 21:22

    Shortest way:

    String toMD5(String input) {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] raw = md.digest(input.getBytes());
        return DatatypeConverter.printHexBinary(raw);
    }
    

    Just remember to handle the exception.

提交回复
热议问题