| package cc.mrbird.febs.pay.util; | 
|   | 
| import cc.mrbird.febs.common.exception.JPException; | 
| import cc.mrbird.febs.pay.model.Algorithm; | 
| import cc.mrbird.febs.pay.model.CommonConst; | 
| import cn.hutool.core.util.StrUtil; | 
|   | 
| import java.io.UnsupportedEncodingException; | 
| import java.security.MessageDigest; | 
| import java.security.NoSuchAlgorithmException; | 
|   | 
| /** | 
|  * MD5工具类 | 
|  * @author chenyf | 
|  * @date 2018-12-15 | 
|  */ | 
| public class MD5Util { | 
|   | 
|     /** | 
|      * 生成16进制的MD5字符串 | 
|      * @param str | 
|      * @return | 
|      */ | 
|     public static String getMD5Hex(String str) { | 
|         return HEXUtil.encode(getMD5(str), true); | 
|     } | 
|   | 
|     public static byte[] getMD5(String str) { | 
|         MessageDigest messageDigest; | 
|         try { | 
|             messageDigest = MessageDigest.getInstance(Algorithm.MD5); | 
|             messageDigest.reset(); | 
|             if (StrUtil.isNotEmpty(str)) { | 
|                 messageDigest.update(str.getBytes(CommonConst.ENCODING_UTF_8)); | 
|             } | 
|         } catch (NoSuchAlgorithmException e) { | 
|             throw new JPException("生成MD5信息时异常", e); | 
|         } catch (UnsupportedEncodingException e) { | 
|             throw new JPException("生成MD5信息时异常", e); | 
|         } | 
|   | 
|         return messageDigest.digest(); | 
|     } | 
| } |