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