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