MD5加密组件 @author SeanDragon
| 13 | * @author SeanDragon |
| 14 | */ |
| 15 | public final class ToolMD5 { |
| 16 | private ToolMD5() { |
| 17 | throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * MD5加密 |
| 22 | * |
| 23 | * @param data |
| 24 | * 待加密数据 |
| 25 | * |
| 26 | * @return byte[] 消息摘要 |
| 27 | * |
| 28 | * @throws NoSuchAlgorithmException |
| 29 | */ |
| 30 | public static byte[] encodeMD5(byte[] data) throws NoSuchAlgorithmException { |
| 31 | // 加入BouncyCastleProvider支持 |
| 32 | Security.addProvider(new BouncyCastleProvider()); |
| 33 | |
| 34 | // 初始化MessageDigest |
| 35 | MessageDigest md = MessageDigest.getInstance("MD5"); |
| 36 | |
| 37 | // 执行消息摘要 |
| 38 | return md.digest(data); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * MD5加密 |
| 43 | * |
| 44 | * @param data |
| 45 | * 待加密数据 |
| 46 | * |
| 47 | * @return String 消息摘要 |
| 48 | * |
| 49 | * @throws NoSuchAlgorithmException |
| 50 | */ |
| 51 | public static String encodeMD5Hex(byte[] data) throws NoSuchAlgorithmException { |
| 52 | // 执行消息摘要 |
| 53 | byte[] b = encodeMD5(data); |
| 54 | |
| 55 | // 做十六进制编码处理 |
| 56 | return new String(Hex.encode(b)); |
| 57 | } |
| 58 | |
| 59 | } |
nothing calls this directly
no outgoing calls
no test coverage detected