---
title: "java中string转码md5"
author: "Cesar28"
date: "2015-08-27T14:09:48Z"
tags: []
categories: ["编程语言"]
slug: "java-string-md5"
draft: false
lastmod: "2015-08-27T14:09:48Z"
id: 2238356
url: "https://cesar28.iteye.com/blog/2238356"
---

不说了，直接上代码：
public final static String MD5(String s) {
        char hexDigits={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};      
        try {
            byte btInput = s.getBytes("utf-8");
            MessageDigest mdInst = MessageDigest.getInstance("MD5");
            mdInst.update(btInput);
            byte md = mdInst.digest();
            int j = md.length;
            char str = new char;
            int k = 0;
            for (int i = 0; i < j; i++) {
                byte byte0 = md*;
                str = hexDigits;
                str = hexDigits;
            }
            return new String(str);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }