MD系列加密组件 Tiger、Whirlpool和GOST3411共3种算法 @author SeanDragon
| 14 | * @author SeanDragon |
| 15 | */ |
| 16 | public final class ToolMD { |
| 17 | |
| 18 | private ToolMD() { |
| 19 | throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); |
| 20 | } |
| 21 | |
| 22 | |
| 23 | /** |
| 24 | * Tiger加密 |
| 25 | * |
| 26 | * @param data |
| 27 | * 待加密数据 |
| 28 | * |
| 29 | * @return byte[] 消息摘要 |
| 30 | * |
| 31 | * @throws Exception |
| 32 | */ |
| 33 | public static byte[] encodeTiger(byte[] data) throws NoSuchAlgorithmException { |
| 34 | |
| 35 | // 加入BouncyCastleProvider支持 |
| 36 | Security.addProvider(new BouncyCastleProvider()); |
| 37 | |
| 38 | // 初始化MessageDigest |
| 39 | MessageDigest md = MessageDigest.getInstance("Tiger"); |
| 40 | |
| 41 | // 执行消息摘要 |
| 42 | return md.digest(data); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * TigerHex加密 |
| 47 | * |
| 48 | * @param data |
| 49 | * 待加密数据 |
| 50 | * |
| 51 | * @return byte[] 消息摘要 |
| 52 | * |
| 53 | * @throws Exception |
| 54 | */ |
| 55 | public static String encodeTigerHex(byte[] data) throws NoSuchAlgorithmException { |
| 56 | |
| 57 | // 执行消息摘要 |
| 58 | byte[] b = encodeTiger(data); |
| 59 | |
| 60 | // 做十六进制编码处理 |
| 61 | return new String(Hex.encode(b)); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Whirlpool加密 |
| 66 | * |
| 67 | * @param data |
| 68 | * 待加密数据 |
| 69 | * |
| 70 | * @return byte[] 消息摘要 |
| 71 | * |
| 72 | * @throws Exception |
| 73 | */ |
nothing calls this directly
no outgoing calls
no test coverage detected